I'm developing a project in java and putting images in jLabels
, however, every time I run the program, it displays a message " Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
" and does not execute, loads up to 50 %.
When I go into properties of jLabel, I click icon and reset as default, jLabel is left without image and the program runs normally.
During my search I found people talking about how my code was returning null in the image ... The following code:
jLabelImgLogoInicial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/gui/img/logoempregoinicial.png"))); // NOI18N
My problem is that the right path to the image would be " /img/logoempregoinicial.png
", but when I insert the image, netbeans automatically creates the address of the previous code and returns null because it will not find the image .
The architecture image of my project follows:
Thestackoferrorsfollows:
Exceptioninthread"AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at view.gui.LogoInicial.initComponents(LogoInicial.java:47)
at view.gui.LogoInicial.<init>(LogoInicial.java:20)
at view.gui.MainEmpreGO.<init>(MainEmpreGO.java:19)
at view.gui.MainEmpreGO$6.run(MainEmpreGO.java:278)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I have read that in order to solve this problem, it is necessary to save the images in a netbeans "bin" folder, but I did not find this folder.
How do I find the netbeans bin folder to save the image and this problem no longer occurs and why it is necessary to save specifically in this folder so that the program does not put a path different than what I need?
Source searched: Why does my icon handling code throw a NullPointerException?