0

i'm new to Java and I tried to design a form. So i have designed the background and set a Jlabel icon to use the image as background. it work .

then i change to another image ( same design just a simple edit ) but now it doesn't work. it work if i change to the original image.

I'm stuck here because i don't know where to fix this. Please help

Here is the code that i use :

bg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/bgimage.png")));

and here is the error :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>
mbuhasu
  • 101
  • 1
  • 7
  • Your question is a duplicate of thousands, and it's all about using the correct path to an existing, non-corrupt image file. We have no idea what your path structure is like, if your path String is correct, if the image file is corrupt, none of this. – Hovercraft Full Of Eels May 28 '18 at 20:11
  • Also, when you load from classpath, make sure is the full package.`getClass().getResource("/com/myapp/foopackage/barimg.png") – George Z. May 28 '18 at 20:13
  • Thanks for the help , i have said before that the only thing i changed in code is the file name and its error, if changed the file name back to original image , it work. the image it self is okay and i can open it with image viewer. Please help – mbuhasu May 28 '18 at 20:15
  • Look at the duplicates and *study* the answers. Also have a look at [this related question](https://stackoverflow.com/questions/13269556/strange-behavior-of-class-getresource-and-classloader-getresource-in-executa) and its answers. Some are stellar. – Hovercraft Full Of Eels May 28 '18 at 20:19
  • Thanks for the help, i just tried closing Sketch and netbeans , re export the design , and re-run the file . now it works :) . still don't know what's going on haha – mbuhasu May 28 '18 at 20:29

0 Answers0