| Author |
Problem getting image from JAR file
|
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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
Joined: Jul 20, 2001
Posts: 84
|
|
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
Joined: Jul 11, 2001
Posts: 15230
|
|
|
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
Joined: Oct 18, 2000
Posts: 4121
|
|
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
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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.
|
 |
 |
|
|
subject: Problem getting image from JAR file
|
|
|