NullPointerException when accessing image files in a .jar file
Posted
by
user548240
on Stack Overflow
See other posts from Stack Overflow
or by user548240
Published on 2010-12-24T23:45:12Z
Indexed on
2010/12/24
23:54 UTC
Read the original article
Hit count: 143
Hi,
I have pretty much tried everything but still have this same problem. I have the following setup: I have a images.jar containing a folder called 'images' in which there are multiple image files. I add images.jar to the java build path of the project in eclipse, and i've been trying to use the following code to access the individual images in the jar:
URL url = this.getClass().getResource("images/a.png");
ImageIcon icon = new ImageIcon (url);
Unfortunately, the URL object is always NULL. I don't think this has anything to do with where I put images.jar file as it is added to the classpath in eclipse. I have also tried using the path '/images/a.png', but still the same problem. Any suggestion would be extremely welcome! Thanks.
© Stack Overflow or respective owner