Win a copy of Spring in Action (5th edition) this week in the Spring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Problem getting image from JAR file  RSS feed

 
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.
 
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.
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!