Search code examples
javaswingimageicon

Errors in running a file in NetBeans 6.5.1


I've got this "CustomerLogin" application that i designed using NetBeans 6.5.1. The code shows no errors. But it still doesn't run. It shows some things in the output space on the bottom of the screen. What are all these? What should I do? Here's what is displayed in the output window:

init:
deps-jar:
compile-single:
run-single:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
        at CustomerLogin.initComponents(CustomerLogin.java:65)
        at CustomerLogin.<init>(CustomerLogin.java:22)
        at CustomerLogin$3.run(CustomerLogin.java:151)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 1 second)

This is the code that shows error:

jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/user-login_icon.png"))); // NOI18N

Solution

  • The image is in a file on the desktop. I've used the same file to import it on to the form. – LuluLala 1 min ago

    From that comment, what you'll need to do is copy the image you want in your project, somewhere like scr/main/java/resources/images and then get that image, from your project folder, for your icon. That will change the path that Netbeans generate to a valid one.

    I doubt you got your desktop folder as a source folder for your project, meaning the image isn't in your project jar file.