File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception

 
Adam Polak
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic