4
I’m developing a project in java and placing images in jLabels
, however, every time I run the program, it appears a message "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
" and does not perform, loads up to 50%.
When I go into jLabel properties, I click icon and reset to default, jLabel runs without image and the program runs normally.
During my research I found people saying that my code was returning null in the image... Follow the code:
jLabelImgLogoInicial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/gui/img/logoempregoinicial.png"))); // NOI18N
My problem is that the right path to image would be "/img/logoempregoinicial.png
", however, when I insert the image, netbeans automatically creates the previous code address and results in null return, as it will not find the image.
Follow the image of the architecture of my project:
Follows the stack of errors:
Exception in thread "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 read that to solve this problem, it is necessary to save the images in a netbeans "bin" folder, but I did not find this folder.
How to find the netbeans bin folder to save the image and this problem does not occur anymore 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?
Where is the stack of errors?
– user28595
I forgot to post the print, I will edit the question with print @Renan
– Marcielli Oliveira
edited the question with the @diegofm bug stack
– Marcielli Oliveira
Have you tried to pass the path through code, not through the netbeans editor? And confirm there where line 47 of the Logoinitial class is.
– user28595
I’ll run tests here for code. Line 47 is the same "jLabelImgLogoInicial.setIcon(new javax.swing.Imageicon(getClass().getResource("/view/Gui/img/logoempregoinicial.png")); // NOI18N"
– Marcielli Oliveira
Change the address to
/main/java/view/gui/img/logoempregoinicial.png
– user28595
Is using the
build.xml
generated by Netbeans to build the . jar, right? Have you made any modifications or are you "the way it is"? Just so you know, I think you can formulate an answer.– Renan Gomes
I’m doing tests @diegofm thanks for the tips.
– Marcielli Oliveira
@Renan am using the default netbeans option, but feel free to post your answer, maybe I’ll try it your way and fix my problem.
– Marcielli Oliveira