r/javahelp • • Sep 04 '16

GUI programming not working properly.

Why am I getting a null pointer exception? Netbeans is not flagging any errors after I've written the code. I'm getting a null pointer pointer exception, whatever that is.

Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:217) at LabelFrame.LabelFrame.<init>(LabelFrame.java:34) at LabelFrame.LabelTest.main(LabelTest.java:13)

Label Frame test class http://pastebin.com/d1bQ11ae Label Frame http://pastebin.com/UQGVNh2f

0 Upvotes

3 comments sorted by

5

u/nutrecht Lead Software Engineer / EU / 20+ YXP Sep 04 '16

I'm getting a null pointer pointer exception, whatever that is.

And why did you not google "what is a null pointer exception"?

It means that you have an object reference somewhere you didn't actually assign an object to and then try to call a method on that 'empty' (null) reference. The stacktrace tells you exactly where it happens.

2

u/ElFeesho Sep 04 '16

If your first response is to ask for help, you're going to struggle learning how to problem solve on your own.

Converting a specific error message into something you can google for is a skill that will take you far.

Learning new concepts every day will take you further. You will build a vocabulary for concepts and then when you hit a new situation, you will have a repertoire of experience to fall back on and likely a similar issue you faced one time will map onto this seemingly new problem.

1

u/Yeshua7474 Sep 04 '16

start the Image icon path with a forward slash like: "/bug.jpg"