Images not showing up in JAR file!
Author |
Message |
SJ
|
Posted: Fri Mar 20, 2009 5:59 pm Post subject: Images not showing up in JAR file! |
|
|
I just made a small program to test loading images, it works fine in Eclipse, but when I export it to a jar, the images no longer show up! (the jar file runs, but the images just dont show)
I did some research too, it seems like I need to use this...
ClassLoader cl = this.getClass().getClassLoader();
ImageIcon icon = new ImageIcon(cl.getResource("imgs/someImg.png"));
instead of my original code,
ImageIcon icon = new ImageIcon("imgs/someImg.png");
but the first one doesnt even work - it throws a null pointer excpetion because it doesnt even find the image!
My source code are all in src folder, all images are in the imgs folder. I'm wondering maybe it's something to do with the path of these things?
Help please! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Fri Mar 20, 2009 7:12 pm Post subject: RE:Images not showing up in JAR file! |
|
|
are src and imgs in the same folder, or is imgs in source? Because right now, imgs would have to be in src for it to work. Eclipse stores it as a project, and automatically goes to that folder. I think it's "../imgs/someImg.png". Maybe not. There is a command to go up one file though. |
|
|
|
|
![](images/spacer.gif) |
btiffin
![](http://compsci.ca/v3/uploads/user_avatars/189169540547b535e50e4a7.jpg)
|
|
|
|
![](images/spacer.gif) |
SJ
|
Posted: Fri Mar 20, 2009 11:11 pm Post subject: RE:Images not showing up in JAR file! |
|
|
Thank you so much insectoid! I put the imgs folder in the src folder and it worked
and thanks btiffin, interesting page, i'll be sure to study it later |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Mar 21, 2009 11:56 am Post subject: RE:Images not showing up in JAR file! |
|
|
It's good practice to only put source in the src folder, binaries in the bin folder and images in the imgs folder, etc. the ../ is the way to go (if it works in java....) |
|
|
|
|
![](images/spacer.gif) |
|
|