• Some images are not showing when I start my game through its jar file (Java)
    16 replies, posted
I am currently working on a project with a few others. Everything has went on smoothly until now. When I run the project in NetBeans, everything is working as intended. All images show up like they should. If I start the jar file with the console commands (java -jar filename.jar), everything works fine too. BUT, when I doubleclick the jar file itself, some images are not showing up. The code for some of those images are identical to others. I've doublechecked this multiple times, and I have no idea what's wrong. Does anyone know what could be wrong here?
Where are the images and how are you loading them?
The files are located at [I]<root>/images/internal[/I]. They are loaded with this code: [lua]ImageIcon imageIcon = new ImageIcon(System.getProperty("user.dir")+"\\images\\internal\\"+in_imageName); image = imageIcon.getImage();[/lua]
Does it throw any exceptions? Try if it can even find the file with new File("path/to/image.png").exists() and you could try loading it with ImageIO.read(...)
new File("path/to/image.png").exists() returns true, both when the image is actually showing and when it's not
[QUOTE=Acegikmo;19259477]new File("path/to/image.png").exists() returns true, both when the image is actually showing and when it's not[/QUOTE] Did you try loading it with ImageIO.read(pathToImage)? If you did and it didn't work, try to check if the loaded image is null.
If I insert this code: JOptionPane.showMessageDialog(parent, ImageIO.read(new File(path))); It shows all the info on the image (When I run it through NetBeans). When I doubleclick the jar file, nothing shows up. The program seems to close itself.
Can you show me the source code? I could try running it myself.
[QUOTE=Robber;19260136]Can you show me the source code? I could try running it myself.[/QUOTE] The source code is really long, I don't think it'll help. A little something I noticed; if I try the ImageIO thing on images that work, the jar file doesn't start anyway. What puzzles me is that I've got two sets of images. Two left images and two right images. They are idendically written, except that the name is left instead of right. They both work perfectly fine if I start the jar file through cmd (java -jar fileName.jar). They both work perfectly fine if I start the game through my IDE. Only when I start it by doubleclicking the jar file, the left images are not showing up.
Wow, that's really weird. Sorry, but I have no idea what's causing this.
Alright, thanks for the help anyway!
In the end, you can just just make something like run.bat: [code] java -jar your_jar_file.jar [/code] That's what most apps seem to do. [editline]08:45PM[/editline] The other question is - does the command javaw -jar your_jar_file.jar have the same issue?
I've already tried making a file run that command line though. It works for me, but not for my friends (For some reason). I haven't done the javaw -jar file.jar command though, I'll try it out tomorrow.
[QUOTE=Acegikmo;19267719]I've already tried making a file run that command line though. It works for me, but not for my friends (For some reason).[/QUOTE] Then that's probably the issue... make sure that the directory structure is as you expect it when ran on your friend's comps.
Are your images packaged inside your jar? You can use the command jar tf JAR_FILE_HERE to see the contents of the jar. If they are in your jar, I would guess that it's a filepath issue. You could try using the Class.getResource method, so you don't have to deal with user.dir
Nope, the images are loaded outside the jar file
[QUOTE=nullsquared;19274445]Then that's probably the issue... make sure that the directory structure is as you expect it when ran on your friend's comps.[/QUOTE] Java may not be in their path...
Sorry, you need to Log In to post a reply to this thread.