Okay, here goes:
I'm trying to load two images from a .jar file that contains two folders (and the META-INF, but that doesn't matter in this situation), volatileimagetest (where the code is) and images (where the two images are).
When I run the code (below) before it's packaged into a .jar, it runs just fine. I have two directories, volatileimagetest (where the code is) and images (where the two images are). The directories are exactly the same as in the .jar, but not in a jar file.
Now I saw on
http://weblogs.java.net/blog/chet/archive/2004/08/toolkitbuffered.html that to load images from within a .jar file, I should use the code (slightly modified of course):
1 2
| URL url = getClass().getResource("/images/img1.png"); BufferedImage img = ImageIO.read(url); |
This loads the images when running outside the .jar file. I printed url to System.out, and got this: "file:/C:/Documents%20and%20Settings/Owner/My%20Documents/Java/VolatileImage/build/classes/images/img1.png". I feel I should just say the directory volatileimagetest is located in the same directory as images, and contains all class files.
When I run this as a .jar, I get a NullPointException, and I narrowed it down to the line "URL url = getClass().getResource("/images/img1.png");", with getResource() returning null.
Has anyone experienced this, and if so could they please help
