Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image doesn't come up from the jar

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi Everybody,


My program should show some stuff in the main area including an image (a gif file). It works when I run it from within Eclipse or when it starts from a command prompt window (OS WinXP).

With Eclipse I've created an executable jar file but when I try to run the program from the jar it shows everything but the image. I checked if the image got into the jar and it did.

Here are the code lines dealing with the image:

Code:
image=getToolkit().getImage(getClass().getResource("myImage.gif"));

...

g2d.drawImage(image, 0, 0, areaWidth,this.getHeight(), this);


Any idea what is wrong?


Thanks,

Alex
 
Hi Dian,

Thanks for your response.

I didn't do anything special about the path. In the jar it is in the same folder with the class files.

What do I do? Should it be something like this:

image=getToolkit().getImage(getClass().getResource("c:\somefolder\myImage.gif"));

???


Thanks,

Alex
 
If the image is under the path in the jar :

acme\com\images

try :

image=getToolkit().getImage(getClass().getResource("\acme\com\images\myimage.gif");



--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
or rather :

image=getToolkit().getImage(getClass().getResource("/acme/com/images/myimage.gif");

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thank you Sedj,


Please excuse my stupidity, but the thing is that the jar doesn't contain any directories. All class files and the image are in one place. Before I had a separate folder for the manifest but now even this is in the same spot with the other files.

More ideas?

Ales

 
Have you tried this?
Code:
image=getToolkit().getImage(getClass().getResource("/myImage.gif"));

Tim
 
Hi Tim,

Thanks for getting into it.

I did what you suggested, even trying different slashes '/' and '\'. Still no effect...

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top