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 › Array of objects Null Pointer Exception
Page Index Toggle Pages: 1
Array of objects Null Pointer Exception (Read 870 times)
Array of objects Null Pointer Exception
Mar 29th, 2010, 1:22pm
 
Hi,

the following code returns a Null Pointer Exception, and I think it is the way I have initialised the array. Any Tips?

Die[] dice;//Declare the array

int numdice = 10;
int i = 100;

void setup() {
 size(100,10);
 noStroke();
 }
void draw() {
 dice= new Die[numdice];
 TuioProcessing tuioClient = new TuioProcessing(this);
 myBus = new MidiBus(this,"IAC Bus 1","IAC Bus 1");// Create a new MidiBus object
 for (int i=0; i< dice.length; i++) {
   //load dice details into array???
   dice[i] = new Die(tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngle() );
 }

Thanks,
Russell
Re: Array of objects Null Pointer Exception
Reply #1 - Mar 29th, 2010, 2:06pm
 
Your syntax is OK. You should put those 3 lines into setup(), though :

Code:
dice = new Die[numdice];
TuioProcessing tuioClient = new TuioProcessing(this);
myBus = new MidiBus(this,"IAC Bus 1","IAC Bus 1");


and not in draw().

Oh, and you should call a dice a Dice, and not a Die. Makes more sense.
Page Index Toggle Pages: 1