| Author |
Null Pointer Exception
|
Adam Polak
Greenhorn
Joined: Oct 28, 2002
Posts: 23
|
|
I have a null pointer exception when pressing on a button in the following applet, can someone help me out with this: [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ March 24, 2003: Message edited by: Dirk Schreckmann ]
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3028
|
|
Originally posted by Adam Polak: I have a null pointer exception when pressing on a button in the following applet, can someone help me out with this: public void actionPerformed( ActionEvent event){ if (event.getSource()== codeerKnop){ String codeerString = ( r1.encode( invoerVeld.getText() ) ); gecodeerdVeld.setText(codeerString); } if (event.getSource()== decodeerKnop){ String decodeerString = ( r1.decode( invoerVeld.getText() ) ); gedecodeerdVeld.setText(decodeerString); } }
You are trying to refernce an object of a String that has not been created. Likely candidates are: r1 when you do r1.encode or r1.decode. The text returned from invoerVeld, when you do getTest() it can return a null. Look at the error. It should give you a line number. Go to that line and see which object is not yet defined (I would guess r1). If it is r1, remeber you have to initialize r1 with r1=new Reverse() (or whatever it is) somewhere BEFORE you ever use it. You can check the text by enclosing all the actionPerformed statements into an: if (invoerVeld != null) { block.
|
Steve
|
 |
 |
|
|
subject: Null Pointer Exception
|
|
|