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.
IndexProgramming Questions & HelpSyntax Questions › Pimage array NullPointerException
Page Index Toggle Pages: 1
Pimage array NullPointerException (Read 571 times)
Pimage array NullPointerException
Mar 28th, 2010, 4:32pm
 
I am trying to create a panoramic view with Pimage array. However, I keep getting a null pointer exception error. I believe this is due to the variable scope. Which I do not understand because I have it set to global.

Thanks for any help in advance!

The code is below:
Code:
// Grant Windes
// Lab - 08 panoramic

// Global variable declarations
PImage[] panorama;

// Initialize variables
void setup()
{
//window setup
size(800,533);
frame.setTitle("Pretty Pictures");

//load images
PImage[] panorama = new PImage[16];
panorama[0] = loadImage("IMG_00.JPG");
panorama[1] = loadImage("IMG_01.JPG");
panorama[2] = loadImage("IMG_02.JPG");
panorama[3] = loadImage("IMG_03.JPG");
panorama[4] = loadImage("IMG_04.JPG");
panorama[5] = loadImage("IMG_05.JPG");
panorama[6] = loadImage("IMG_06.JPG");
panorama[7] = loadImage("IMG_07.JPG");
panorama[8] = loadImage("IMG_08.JPG");
panorama[9] = loadImage("IMG_09.JPG");
panorama[10] = loadImage("IMG_10.JPG");
panorama[11] = loadImage("IMG_11.JPG");
panorama[12] = loadImage("IMG_12.JPG");
panorama[13] = loadImage("IMG_13.JPG");
panorama[14] = loadImage("IMG_14.JPG");
panorama[15] = loadImage("IMG_15.JPG");
}

// Animation/drawing code
void draw()
{
displayImages();
}

void displayImages(){

for(int i=0; i<16; i++){
image(panorama[i], 0, 0);
}

}
Re: Pimage array NullPointerException
Reply #1 - Mar 28th, 2010, 4:37pm
 
remove PImage[] from      PImage[] panorama = new PImage[16];
cause there you set it local again.

btw, you could easily load your images with a loop instead of 16 lines
Re: Pimage array NullPointerException
Reply #2 - Mar 28th, 2010, 4:47pm
 
Ahh I see why its set to local because it is reintializing it. I know a bout the loop I took it out of the loop to make sure the loop wasn't the problem! Thanks for the help!
Page Index Toggle Pages: 1