Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 974
1
  • 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 ]
 
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic