Exception in thread "main" java.lang.NullPointerException running the JButton program

0 Legos Bo · April 26, 2015
Hi there,

Just watched the video and rewrote it in my Eclipse Luna IDE, but i'm getting the following error when running it:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at JButton.Gui.<init>(Gui.java:37)
at JButton.App1.main(App1.java:10)

All my lines of code are exactly the same as those from Bucky in the tutorial, but still my program doesn't seem to work!! Any Idea?

In advance thank you for the Help,


Post a Reply


Oldest  Newest  Rating
0 Nicholas Eason · April 27, 2015
at JButton.Gui.(Gui.java:37)

at JButton.App1.main(App1.java:10)

Initialize the JButton referenced at line 37 in your Gui class.
0 Kuroodo Ditory · April 27, 2015
This is a Java forum, not a forum dedicated to one video. What video are you talking about?

Also the reason why nobody replied to you is because you didn't post any code. It's like going to a mechanic and saying that your car isn't working, but you never took your car over to him so that he could inspect it.

A null pointer exception happens when something is null. It usually happens when you forget to initialize your variables and objects.

Make sure you initialized everything needed to be initialized, before you use them.

By initialize I mean:

JButton myButton = new JButton();
ImageIcon myIcon = new ImageIcon();

  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator