This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ImageIcon NullPointerException

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a program that I developed in Eclipse, which runs great. However, when I export it to a jar file(all resources included), it keeps giving me an error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source)

I checked the jar file to make sure the image is in there, and it is.
Any suggestions? I'm stumped. Here's the code causing the error:



ApplicationConstants.cancel is a static variable - see below:


Thanks!
[ February 20, 2006: Message edited by: Jennifer Sohl ]
 
vinodkumar kolakampadam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jeni

Modify your code
from
cancel = new JCheckBox("Cancel PO",new ImageIcon(getClass().getResource(ApplicationConstants.cancel)));


to

cancel = new JCheckBox("Cancel PO",new ImageIcon(getClass().getClassLoader().getResource(ApplicationConstants.cancel)));

you have to the get the classloader to load the images
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response! I haven't tried that yet, but did find something interesting (and weird). I tried all of my other images that I had in Eclipse and they all worked with the code that I currently have. I could not think of anything else, so just for craps and giggles, I renamed the image from cancel.jpg to redx.jpg, then exported it to a jar file and it worked! Not sure why, though. That'll be something to ponder later this week.
Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic