getValue() null pointer

SteveBeard11's icon

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

441.GUICW6.java
java
pgk's icon

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

SteveBeard11's icon

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!

jan.jdo's icon

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

SteveBeard11's icon

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