In Processing, I have an ArrayList of objects built from a custom class. When I use the .get()
function to return one of the objects, it seems to return the object all right -- but I can't access any of the object's variables or methods. I get the error message "[variable] cannot be resolved or is not a field." Is this a bug, or am I doing something wrong?
Here's a sample. Notice the values returned from the setup()
function.
// regular array
Thing[] thinglist1 = new Thing[1];
// ArrayList array
ArrayList thinglist2 = new ArrayList<Thing>(1);
// instantiate the class
Thing thing = new Thing(12345);
// class definition
class Thing {
int var;
Thing(int i){
var = i;
thinglist1[0] = this;
thinglist2.add(this);
};
};
// run it!
void setup(){
println(thinglist1[0] == thinglist2.get(0));
// true
println(thinglist1[0].var);
// 12345
println(thinglist2.get(0).var);
// ERROR: "var cannot be resolved or is not a field"
};