I have created an array of custom objects in my processing code and then proceed to init it. However, for some reason I run into a null pointer exception at: objectArray[i].siteID = 5;
I have spent the last 2 hours trying to find info on how to fix this but the syntax seems to be correct!
Code:
class TtalkObject{
int siteID = 0;
String URL = "test";
int commentNum = 5;
int averageLength = 5;
}
PFont f;
TtalkObject[] objectArray;
int whatObjectPart = 0;
int whatObject = 0;
void setup()
{
size(300,300);
f=createFont("Arial",16,true);
objectArray = new TtalkObject[50];
for (int i = 0; i < 50; i ++){
objectArray[i].siteID = 5;
objectArray[i].URL = "test";
objectArray[i].commentNum = 10;
objectArray[i].averageLength = 10;
}
}
Looks like you’re never creating an instance of your
TtalkObject, you’re just initializing an array to hold fifty of those objects.I’m not familiar with java syntax, in c# it’d be