Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton not displaying, throwing NullPointerException

 
Justin Dutch
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?

 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • 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.
 
Rob Camick
Ranch Hand
Posts: 2616
9
  • 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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic