• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems loading images from application JAR

 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Swing application that uses some images and icons. When I run it from an exploded directory, everything works fine. But when I run the exact same code from a jar, the ImageIcon objects do not have an image. The images are being found in the JAR (see logging output below) by the call to getResource(), but loading them fails. The code, logging output, and jar structure is shown below.

The code I am using is right out of the Java Tutorial's How to Use Icons. And that the tutorial explicitly states that the getResouce() will work for images contained in the application jar file; which it is. But the ImageIcon constructor, which I believe uses MediaTracker behind the scenes, is not loading the image. I really don't know where to go from here. Any help is appreciated.



Logging Output when in exploded directory, and loading image is successful:



Logging Output when in jar, and loading image is unsuccessful:


JAR Structure:

[ May 13, 2008: Message edited by: Mark Vedder ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Vedder:
I have a Swing application that uses some images and icons. When I run it from an exploded directory, everything works fine. But when I run the exact same code from a jar, the ImageIcon objects do not have an image. The images are being found in the JAR (see logging output below) by the call to getResource(), but loading them fails.



Could the images be corrupted in the JAR? Can you see them
in a web browser after manually extracting them from the JAR?
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Cole:


Could the images be corrupted in the JAR? Can you see them
in a web browser after manually extracting them from the JAR?



Nice call Brian.

It does indeed seem that the images are corrupt in the JAR. Upon extracting the JAR, I could not view them in a browser nor an image editor. Then I looked at them closer, and their files sizes did not match the originals. So now I need to determine what is happening in the Ant build that is corrupting the images. I have a thought as to what it may be, and will look into it.

Thanks again! I never even thought to check the actual images themselves. I just assumed there was an issue with the code. D'Oh! A nice reminder of not jumping to conclusions when debugging
[ May 14, 2008: Message edited by: Mark Vedder ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic