I'm trying to learn Java and am having problems with a simple applet I am authoring, the purpose of this simple applet is to flip through images passed to the applet as parameters every few seconds. Everything compiles fine but when I try to run it through the appletviewer I get a NullPointerException on the boldface line below...
Code:import java.awt.*; import java.applet.*; import java.util.*; public class ImageFlip extends Applet { private Image imgs[]; private int numimgs = 0; private int curimg = 0; public void init() { String name; for(numimgs = 0; (name = getParameter("img" + numimgs)) != null; ++numimgs); { imgs[numimgs] = getImage(getDocumentBase(), name); } } public void start() { while(this.isActive() == true); { paint(getGraphics()); wait(1000); } } private void wait(int millisecs) { Date dt = new Date(); long strt; strt = dt.getTime(); while(dt.getTime() - strt < millisecs) {} } public void paint(Graphics g) { g.drawImage(imgs[++curimg], 0, 0, 500, 400, this); if((curimg + 1) >= numimgs) {curimg = 0;} } }




Reply With Quote