jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes JButton not displaying, throwing NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton not displaying, throwing NullPointerException" Watch "JButton not displaying, throwing NullPointerException" New topic
Author

JButton not displaying, throwing NullPointerException

Justin Dutch
Greenhorn

Joined: Aug 12, 2013
Posts: 5
Trying to display buttons through a method. Keep getting NullPointerException at line 41. What am I doing wrong?

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2380
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
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:

 
jQuery in Action, 2nd edition
 
subject: JButton not displaying, throwing NullPointerException