# [java] JAR problem

This topic is 4306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Recently I finally made a simple interactive game that collects input and move some objects accordingly. It works in Eclipse IDE, but when I JAR it (using Eclipse export function) and runs it a little problem appears. The game does not display any of the images, all I can see is a flashing screen. I cannot figure out what is wrong, the images are inside the jar file in the correct directory, no exceptions, its outputting correct messages. Everything works except the images are not there... Can someone kindly point out what maybe the problem. Thanks in advance

##### Share on other sites
How are you loading your images (post code if possible)? The usual way is to load them from the classpath (eg. getClass().getClassloader().getResourceAsStream() ). Then that'll work both from jar and from disk (for disk you'll probably want to set the classpath to include the root of your data directory.

Other things to watch for are case-sensitive paths (jars are case sensitive, windows isn't), and forward vs. backslash in paths (forward slashes should work everywhere). Also be careful not to have leading slashes for resource paths (eg. "Data/image.png" rather than "/Data/image.png".

Other than that I can only suggest stepping though your loading code and see if anything unexpected crops up.

##### Share on other sites
Sorry for the late reply was quite busy here is my code

bgImage = loadImage("images&#47;background.jpg");Image player1 = loadImage("images&#47;player1.png");Image player2 = loadImage("images&#47;player2.png");Image player3 = loadImage("images&#47;player3.png");private Image loadImage(String filename){	return new ImageIcon(filename).getImage();}

##### Share on other sites
And...? What does getImage return? Have you tried to debug this yourself yet?

Personally I'd switch to using ImageIO.read(URL). Then if it fails you should get a slightly more descriptive exception being thrown rather than just failing silently.

##### Share on other sites
getImage() will return a simple ImageIcon to be drawn.

I just tried out ImageIO.read() as you suggested and it works, it seems there might be some issues with ImageIcon. I will research more on it to see if its my implementation (I copied an example from a book or some inherent reason that it doesn't work with JAR.

Thanks for the help and tip [smile]

##### Share on other sites
Thanks alot thats very helpful [smile]

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631708
• Total Posts
3001840
×