aspose file tools*
The moose likes Beginning Java and the fly likes Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Null Pointer Exception" Watch "Null Pointer Exception" New topic
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: 3946
    
  17

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Exception
 
Similar Threads
set Focus in Border Layout
How to create this simple program in Java?
Some abstract methods from standard API: how to find where implemented?
javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL ci
Calculator - Stacks