| Author |
NullPointerException received trying to change the button label
|
Douglas Walters
Greenhorn
Joined: Nov 05, 2008
Posts: 2
|
|
I'm getting a java.lang.NullPointerException error during runtime when trying to change the button text when clicking the button, eastButton (line 46). I placed a System.out.println statement and the text print with no errors, so I know the coding is correct (with the exception to the setLabel command).
Any ideas?
Thanks
Doug
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
line number 23 i.e. JButton eastButton = new JButton("East"); is creating the problem. This a local declaration which hides the class field eastButton. Change the statement to
eastButton = new JButton("East");
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Douglas Walters
Greenhorn
Joined: Nov 05, 2008
Posts: 2
|
|
Thanks Ankit
This worked. I'm currently going through the Heads Up book and an example they used only displayed the buttons, but no action was attached to them. I went a step foward and added the action, but didn't realize that the JButton within the method over wrote the class button. Thanks again for your help...Doug
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
It's good to experiment with the things Douglas ...
|
 |
 |
|
|
subject: NullPointerException received trying to change the button label
|
|
|