Skip to main content
gamedev.net
🔒 Locked

[java] JAR problem

Started by Si Hao Sep 28, 2006 at 10:14 AM 5 replies 1.6k views
Original Post
Si Hao
Si Hao
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
OrangyTang
OrangyTang
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.
Si Hao
Si Hao
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&#<span class="java-number">47</span>;player2.png"</span>);<br>Image player3 = loadImage(<span class="java-literal">"images&#<span class="java-number">47</span>;player3.png"</span>);<br><br><span class="java-visibilitymodifier">private</span> Image loadImage(String filename){<br> <span class="java-keyword">return</span> <span class="java-keyword">new</span> ImageIcon(filename).getImage();<br>}<br><br></pre></div><!--ENDSCRIPT--> </code></pre></div>
Si Hao
Si Hao
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]
Son of Cain
Son of Cain
Please check this out, might be helpful.
a.k.a javabeats at yahoo.ca
Si Hao
Si Hao
Thanks alot thats very helpful [smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.