Results 1 to 5 of 5

Thread: What am I doing wrong?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    What am I doing wrong?

    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;}
    	}
    
    }
    Last edited by YoungBuck; May 6th, 2001 at 03:52 PM.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width