Sign in to follow this  

[java] JAR problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


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


bgImage = loadImage("images/background.jpg");
Image player1 = loadImage("images/player1.png");
Image player2 = loadImage("images/player2.png");
Image player3 = loadImage("images/player3.png");

private Image loadImage(String filename){
return new ImageIcon(filename).getImage();
}

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this