Search code examples
javaimageimageicon

NullPointerException when using path name to show image in jar file


I have been asked this question before Can not get image from a path, and i try to do the way as this link NullPointerException when using path name to load image file, but it is still not working for me.

I tried delete file and add a new one or create a folder and put this image file in this folder (image/12345.jpg). All those ways are not working.

Could i need to delete all image file and import it all again?? or is there any way i can do it?? Thank you

Because i tried to export exec jar file. it didn't show the image.


Solution

  • try class.getResource("blablabla.png").toURI() and make sure the file is in your classpath. Open the Jar with zip and check.