• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exception in applet

 
Franklin Joe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the following code generate a NullPointerException?
public class SimpleApplet extends java.applet.Applet {
java.awt.Image art;
public void init() {
art = getImage(getDocumentBase(), getParameter("img"));
}
public void paint(java.awt.Graphics g) {
g.drawImage(art, 0, 0, this);
}
}
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javadocs for getImage state that "This method always returns immediately, whether or not the image exists." I would imagine that art would be null if the image doesn't exist, or hasn't yet been loaded. You can check your web server logs for when it is accessed, and whether that access is successful.

You could also use a MediaTracker as described here to make sure the image is loaded before using it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic