We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have created a very simple class that contains a PShape (never mind why). When an instance of the class is initiated, however, I get a NullPointerException when I create the shape. Can you help me understand why this happens?
Here is my code:
MyShape a = new MyShape();
void setup() {
size(400, 400, P2D);
}
void draw() {
a.display();
}
class MyShape {
PShape sh;
MyShape() {
sh = createShape(); //This throws a NullPointerException
sh.beginShape();
sh.vertex(20, 20);
sh.vertex(60, 20);
sh.vertex(60, 60);
sh.vertex(20, 60);
sh.endShape(CLOSE);
}
void display() {
shape(sh);
}
}
Answers
Processing's functions which start w/ create*, load* & save* should not be used before setup() or settings().
Thank you so much! I would have spent ages figuring that out.