We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I'm trying to tidy up a sketch using arrays, in one instance to call multiples of an object, 'SoundObject.' Each object receives data over oscP5. My understanding is that for classes to function with oscP5, you need to declare a 'listener' for each object.
SoundObject[] objects = new SoundObject[7];
void setup() {
for(int i = 1; i < objects.length; i++) {
String x = "/xpos"+i; //unique tags for each instance of class
String y = "/ypos"+i;
String z = "/zpos"+i;
String a = "/amp"+i;
objects[i] = new SoundObject(x, y, z, a, width/2, height/2, 500, 100);
oscP5.addListener(objects[i]); //Doesn't seem to work?
objects[i].id = i;
}
In this code, 'oscP5.addListener(objects[i]);' flags a NullPointerException. Is what I am trying to do even possible? Does the oscP5 library support this approach?
Cheers in advance!
Answers
Have you already created the oscP5 object when you enter this loop?
Of course I haven't! D'oh. Thanks PhiLho. :D
:-)
Technical FAQ: Why do I get a NullPointerException?
Thanks for the link. Super helpful.