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
PImage (Read 542 times)
PImage
Oct 26th, 2006, 12:52pm
 
I have encountered a Null Exception
PImage cloud;
void setup() {
 PImage cloud= new PImage(400,300);
}
void draw() {
 println("cloud width = "+cloud.width); // <---- error
 println("cloud height = "+cloud.height);
}

java.lang.NullPointerException

any suggestion?
Re: PImage
Reply #1 - Oct 26th, 2006, 1:39pm
 
You're defining two different PImages, both called cloud. One globally, one just inside setup.

To show what's going on:

Code:
PImage Global_cloud;
void setup() {
PImage local_cloud= new PImage(400,300);
}
void draw() {
println("cloud width = "+Global_cloud.width); // <---- error
println("cloud height = "+Global_cloud.height);
}


So what you need to do is remove the "PImage" from before cloud within setup(), as then you're assigning to the global cloud, instead of defining a new one.
Page Index Toggle Pages: 1