Win a copy of Securing DevOps this week in the Security forum!
  • 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: 2868
16
  • 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:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!