Need help with loading images in executable Jar

Hi,

I've developed an application using netbeans that needs to load and display images.

I use netbeans Clean and Build function to create an executable Jar file. When I run the executable Jar file it runs fine but when I come to a section of the application that needs images it freezes and can't load the images.

When I then return to netbeans the part of the program that did successfully run before Clean and Build doesn't work anymore and I get an error message saying Uncaught error fetching image:

I use,

URL url = getClass().getResource("images/image1.png");

Image image1 = Toolkit.getDefaultToolkit().getImage(url);

to load an image.

Can someone tell me why, when I clean and build my project to create a JAR, my images fail to load.

Should I be storing the images in a specific folder or something?

Thanks

[911 byte] By [uraknaia] at [2007-10-3 2:56:08]
# 1

I've opened the JAR using winzip and, for some reason, the JAR hasn't preserved my file structure. So, when I try to look for an image as follows:

URL url = getClass().getResource("images/file1.png");

Image img= Toolkit.getDefaultToolkit().getImage(url);

The folder doesn't exist and so it can't find the image.

Can someone tell me how to keep my file structure when I create the JAR or an alternative way to find the images within the JAR file.

Cheers

uraknaia at 2007-7-14 20:45:17 > top of Java-index,Desktop,Deploying...