Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem getting image from JAR file

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JAR and it contains a directory called icons that contains all my image icons for my application.
I am running jdk 1.4.0 and here is the code that is compiling but not running:

Now when I run the applicationa and it gets to this point in the program to load the image this is the error that I get

Can someone help me see the light here? Thanks. If you need any more information let me know.
It is telling me this nullpointerexception on the line Image image = getClass().......
Thanks again.
 
John Smith
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a slightly educated guess, but try replacing the line:

with

Also, make sure your jar file is in the classpath and that inside of the jar file, the file icons/connect16.gif really exists. I had problems getting images out of a jar file a while back and the slash at the beginning (just before icons) did the trick for me. Let me know how it goes...
Randy
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randy, thanks for the guess, but that is not the problem. What I should mention is the fact that it DID work under jdk 1.3 and now with jdk 1.4 it does not.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found a bug report on Sun's site that may be your problem... looks like you might have to parse the URL to get the real path to your file...

-Nate
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That pretty much sums it up Nathan. That pretty much scroggs either me using jdk 1.4 or from storing images in my jar file. I am not going to parse my URL the way they suggest. Seems like too much overhead. I think I will just store the images externally.
Thanks for your reply Nathan. You always have the answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic