File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

JButton not displaying, throwing NullPointerException

Justin Dutch

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

Joined: Sep 13, 2007
Posts: 3130

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 OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Rob Camick
Ranch Hand

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

I agree. Here's the link:
subject: JButton not displaying, throwing NullPointerException
jQuery in Action, 3rd edition