I am currently writing a program that I need to send to a friend as a bank. The program has images that need to be downloaded for the program to work correctly, and I want all this to be contained in one bank. Currently it does not work with an executable bank or when I launch it through the command line. However, he works at netbeans.
Here is the code I'm using:
To upload the image I use:
protected ImageIcon createImageIcon(String path, String description) { java.net.URL imgURL = getClass().getClassLoader().getResource(path); if (imgURL != null) { return new ImageIcon(Toolkit.getDefaultToolkit() .getImage(imgURL),description); } else { System.err.println("Couldn't find file: " + path); return null; } }
for the url that I also tried just
getClass().getResource(path)
The line in which the image should be created is:
this.img =createImageIcon(File.separator+"."+File.separator +"resources"+File.separator+"tiles"+File.separator+"tile.png","tile");
My jar file is installed with a folder containing class files and a resource folder, as at the top level.
I was looking for ways to solve this problem, but I can not find anything that works.
Thanks.
source share