Win a copy of Terraform in Action this week in the Cloud 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

null ImageIcon from getResource in jar

 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following code snippet:

From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.

My class is in "durz.images"; I tried it once with the images in that same directory and just specifying iconName; I tried moving the images to their own "images" subdirectory and specifying "images/" + iconName.

I have verified that the jar file contains the images in the directory path, relative to the root of the jar file, that they're supposed to be in. I did that once when they were in the same directory as the class, and again after I moved them to their own images directory off the directory the class was in.

I am aware that the "/" at the front of the getResource() string parameter means "absolute path within the jar", and without the "/" the path is relative to the path the class is in, in the jar.

Can anyone see what I'm doing wrong here?

rc
 
Saloon Keeper
Posts: 13427
303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ralph. Can you post an SSCCE?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ralph Cook wrote:From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.



How, exactly, did you run the program outside of the IDE? Command line? what command? or did you just double-click an executable jar?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:

Ralph Cook wrote:From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.



How, exactly, did you run the program outside of the IDE? Command line? what command? or did you just double-click an executable jar?



I put it in c:\local, started a dos prompt window, changed my default directory to c:\local, and entered "java -jar durz.jar". The program ran ok, but blew up when I hit this code.

rc
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SSCE helps again; I'm on Windows, and in eclipse, case is not significant on the resource file. It is significant, however, in the jar. So the case of the resource filename must be the same as stored in the jar.

thanks!
rc
 
Stephan van Hulst
Saloon Keeper
Posts: 13427
303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow really? That's an eye-opener for me as well.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If you put "Expanded.GIF" in a sub-directory named "images", it works from a jar unless/until you change the capitalization on the filename.

It makes sense; the zip file format has to be usable across OSs, so it has to handle (and distinguish among) different cases of filename.

rc
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic