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.
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.
Thanks 