I'm trying to load a bitmap into an Image object using the following code:
System.out.println("Point A");
System.out.println("Point B");
m_image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(filename));
System.out.println("Point C");
MediaTracker mt = new MediaTracker(null);
System.out.println("Point D");
mt.addImage(m_image, 0);
System.out.println("Point E");
try
{
System.out.println("Point F");
mt.waitForID(0);
System.out.println("Point G");
}
catch (InterruptedException ie)
{
System.err.println(ie);
System.exit(1);
}
System.out.println("Point H");
m_image is a private java.awt.Image object of the class I'm in and filename is a String argument of the method I'm in. The filename I pass to this method when I call it is the name of a bitmap in the same directory of the .java file. If it matters, I'm using eclipse to run this.
The code gets to point F, and gives me a NullPointerException (or so I think that's the issue, based on my knowledge of Java error output):
Exception in thread "main" java.lang.NullPointerException
at java.awt.ImageMediaEntry.getStatus(MediaTracker.java:908)
at java.awt.MediaTracker.statusID(MediaTracker.java:705)
at java.awt.MediaTracker.waitForID(MediaTracker.java:653)
at java.awt.MediaTracker.waitForID(MediaTracker.java:622)
at Sprite.SetImage(Sprite.java:26)
at Main.main(Main.java:45)
Any help getting the above code to work (or suggesting a alternate method of loading images) is appreciated.