• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException received trying to change the button label

 
Douglas Walters
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Douglas Walters
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good to experiment with the things Douglas ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic