FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   nullpointer exception on new BImage(w,h)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: nullpointer exception on new BImage(w,h)  (Read 496 times)
elout

12747371274737 WWW
nullpointer exception on new BImage(w,h)
« on: Oct 10th, 2003, 6:46pm »

this gives a me a nullpointer exception
Code:

// p5 v.0065
BImage a;
 
void setup()  
{  
  size(200, 200);  
  BImage a= new BImage(32,32);
}  
 
void loop()  
{
  for (int i=0;i<32*32;i++)
  {
 a.pixels[i]=(int) random(255);
  }
  image(a, 0, 0, width, height);
}

 
although this works
Code:

// p5 v.0065
 
void setup()  
{  
  size(200, 200);  
}  
 
void loop()  
{
  BImage a= new BImage(32,32);
  for (int i=0;i<32*32;i++)
  {
 a.pixels[i]=(int) random(255);
  }
  image(a, 0, 0, width, height);
}

 
arielm

WWW
Re: nullpointer exception on new BImage(w,h)
« Reply #1 on: Oct 11th, 2003, 12:56am »

not a bug in processing this time,
 
it's because you declare "a" as a global variable, but inside setup(), you assign a value to a local variable, also named "a" (but not the same one!)
 
solution: inside setup(), remove "BImage" before "BImage a =..."
« Last Edit: Oct 11th, 2003, 12:57am by arielm »  

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »