We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Null Pointer Exception (Read 2041 times)
Null Pointer Exception
Oct 23rd, 2009, 10:00am
 
I'm new to Processing, and while trying to test some of the examples on the processing website, I came across the Sequential animation code

 
int numFrames = 12;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
   
void setup()
{
 size(200, 200);
 frameRate(30);
 
 images[0]  = loadImage("PT_anim0000.gif");
 images[1]  = loadImage("PT_anim0001.gif");
 images[2]  = loadImage("PT_anim0002.gif");
 images[3]  = loadImage("PT_anim0003.gif");
 images[4]  = loadImage("PT_anim0004.gif");
 images[5]  = loadImage("PT_anim0005.gif");
 images[6]  = loadImage("PT_anim0006.gif");
 images[7]  = loadImage("PT_anim0007.gif");
 images[8]  = loadImage("PT_anim0008.gif");
 images[9]  = loadImage("PT_anim0009.gif");
 images[10] = loadImage("PT_anim0010.gif");
 images[11] = loadImage("PT_anim0011.gif");
 
 // If you don't want to load each image separately
 // and you know how many frames you have, you
 // can create the filenames as the program runs.
 // The nf() command does number formatting, which will
 // ensure that the number is (in this case) 4 digits.
 //for(int i=0; i<numFrames; i++) {
 //  String imageName = "PT_anim" + nf(i, 4) + ".gif";
 //  images[i] = loadImage(imageName);
 //}
}

void draw()
{
 frame = (frame+1) % numFrames;  // Use % to cycle through frames
image(images[frame], 50, 50);
}

Each time I copy and paste the code from the website to processing on my computer, I get an error saying Null Pointer Exception for the highlighted line.

Any ideas on how to correct this?

Thanks!
Re: Null Pointer Exception
Reply #1 - Oct 23rd, 2009, 10:43am
 
you dont have the images in your data folder ?
looks like you just copied the code. but you need the images to show them. so replace them with some of your own images...

btw this is not a question to post unter "suggestions / websites"...
Page Index Toggle Pages: 1