Problem with classes and NullPointerException
in
Programming Questions
•
2 years ago
Hello :)
I'm having troubles with classes of "individuals" and "populations" (I use such for an evolutionary strategy). Here is some sample code, the red line gives me a "NullPointerException":
class individual {
int value;
individual() {
value = 0;
}
void show() {
println(value);
}
}
class population {
int pop_size;
individual[] member;
population(int pop_size_init) {
pop_size = pop_size_init;
member = new individual[pop_size];
}
void show_all() {
for (int ind = 0; ind < pop_size; ind++) {
member[ind].show();
}
}
}
population testpop;
void setup() {
testpop = new population(10);
testpop.show_all();
}
void draw () {
}
Could someone please tell me what I did wrong here?
1