getValue() null pointer

Apr 24, 2010 at 4:43pm

getValue() null pointer

I have all but finished creating a GUI Drum Machine in Max Java. However, there is a null pointer statement upon compiling and it won’t accept getValue() in the ChangeListener. If I write simply outlet (16, 88) for example it works, but as soon as I enter JSlider.getValue() it compiles, but gives me pages of errors to do with a null pointer in the max windowupon moving the JSlider.

This correction will help me complete my GUI so any help would me very very very VERY VERY VERY much appreciated!

Thank you very much

SteveBeard11

Attachments:
  1. GUICW6.java
#49981
Apr 24, 2010 at 5:14pm

Hey, what is GUICW6Frame? Max can not find it. Did you mean JFrame? (sorry, just scrolled down… it is an inline class)

#179455
Apr 24, 2010 at 5:21pm

lol yes it is… have u any suggestions to what is wrong? its so confusing because it happened once because i hadnt copied my MaxObject over to the variables to reference in the use of it. But now i have done that it shouldnt be happening!

#179456
Apr 24, 2010 at 7:23pm

hi. inside the GUICW6Frame constructor you have:

JSlider TempoSlider = new JSlider( JSlider.VERTICAL, 0, 1000, 0 );

this is declaring and initialising a variable local to the constructor – the TempoSlider instance variable remainsa null, so, when you later try to call getValue() on the slider you’ll have problems.

just a note – it may be dangerous to open your JFrame from this thread – look into using SwingUtilities.invokeLater(Runnable r) to make the window visble.

Also, in java the convention is to start variable names with lower case.

HTH
jan

#179457
Apr 25, 2010 at 2:16pm

Thank you very much and cheers for the lower case heads up

#179458

You must be logged in to reply to this topic.