• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

images in jar file

hi  
i am loading images into the java file using the following code
ImageIcon icon = new ImageIcon(pics//example.gif)
this works when i compile it however when i export a jar file the pics dont seem to load up
0
isarasoo
Asked:
isarasoo
  • 2
3 Solutions
 
Mayank SAssociate Director - Product EngineeringCommented:
>> ImageIcon icon = new ImageIcon(pics//example.gif)

That won't compile. Do you have "pics/example.gif" or "/pics/example.gif" ? You don't need 2 // over there BTW. What is the hierarchy of the image in the JAR file?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try using:

URL url = getClass ().getResource ( "pics/example.gif" ) ;
ImageIcon icon = new ImageIcon ( url ) ;

Read:

http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html

http://www.rgagnon.com/javadetails/java-0436.html

http://www.rgagnon.com/javadetails/java-0240.html
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
0
 
objectsCommented:
you also need to make sure you include the images in your jar
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now