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 › NullPointerException
Page Index Toggle Pages: 1
NullPointerException (Read 339 times)
NullPointerException
Jun 22nd, 2006, 5:52pm
 
hello,

I wrote a code that will give any pixel one after the other a random greytone. over that i would like to place a picture (.gif) with a green border and an alpha'd rectangle in the middle via a mouseclick.
both parts work when started singular, together processing returns me a "NullPointerException" i don't really get.

Can somebody tell me why it result's and how i can change that ?

Stefan

...

Code:

int x = 0;
int y = 0;

PImage b;

void setup() {
size(512, 384);
/* size(screen.width, screen.height); */
background(255);
noStroke();
colorMode(RGB);
/* framerate(200); */
PImage b = loadImage("testgruen.gif");
}


void draw() {

for(int i=0; i<100; i++) {

float r = random(255);
fill(r); // set Variables fill(r, r, r) for Schwarz/Weiss

if ((x <= width) && (y <= height)) {
rect(x, y, 3, 3);
x++;
}

if (x >= width) {
y++;
x = 0;
x++;
x = x - 1;
}

if (y >= height) {
x = 0;
y = 0;
rect(x, y, 3, 3);
x++;
}
}
if(mousePressed) {
image(b, 0, 0);
}

}
Re: NullPointerException
Reply #1 - Jun 22nd, 2006, 9:10pm
 
You're defining PImage b twice, once globally, and once locally within setup.

The PImage b in setup says "Yes, there'a already something called b, but I want a new thing called b to be a PImage, and have it local to this function only", so all you need to do is remove the "PImage" before the b in setup(), and it should work.
Page Index Toggle Pages: 1