Image Problems...
I am using the following code to try and display an image on a JButton, but the URL is null for some reason...
ImageIcon explosionIcon;
URL url = getClass().getClassLoader().getResource("ExplosionIcon.GIF");
System.out.println(url);
try
{
explosionIcon = new ImageIcon(ImageIO.read(new File(url.toString())));
}
catch(IOException e)
{
System.err.println("Error reading ExplosionIcon.gif");
e.printStackTrace();
return;
}
The image file is in the same file as both the .java and the .class file. Any suggestions?
[602 byte] By [
Rob_Ha] at [2007-11-26 17:02:15]

Just as a test, you can try getting a URL to the .class file itself, and see if it's null.This is one of those grabbing-at-straws tests, but sometimes they help.
> Just as a test, you can try getting a URL to the> .class file itself, and see if it's null.Hardcoding the URL does not seem to work either...
> You can also do this to see where the class exists at
> runtime, then eyeball it to see if the image is
> there. too:
I tried that. My program is laid out like this:
Game
-package1
package2
package3
The image (and the .class) is inside the package2 folder, but when I tried the code you gave me, it returned the URL of the game folder. I'll try to make a jar file (which I was going to do eventually) and see if that makes a difference.