• Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton not displaying, throwing NullPointerException  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to display buttons through a method. Keep getting NullPointerException at line 41. What am I doing wrong?

 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you determine which of those 4 variables is/are null? Once you do you can solve your own problem.

And welcome to the Ranch.
 
Rancher
Posts: 2906
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your addOpButton() method doesn't do what you expect it to do. Java uses "pass by value" so only a copy of the button reference is passed to the method. So your variable still remains null. You need to change your code to something like:

 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!