I am using a java program called Processing (3.2.3), and I am getting a nullpointer when attempting to draw. This has been tested, and is definitely in the rect() call.
Here is my main class:
square[][] squares;
void setup(){
frameRate(30);
size(600, 600, P2D);
background(0);
stroke(255);
int row = 20, col = 20;
squares = new square[row][col];
for (int i = 0; i < row; i = i + 30) {
for (int j = 0; j < col; j = j + 30) {
squares[i][j] = new square(i, j, i+30, j+30, 1);
}
}
}
void draw() {
frameRate(30);
for (int i = 0; i < squares.length; i++) {
for (int j = 0; j < squares[0].length; j++) {
squares[i][j].display();
}
}
}
Here is the square object:
class square {
float x1, y1;
float x2, y2;
int age;
square (float x1, float y1, float x2, float y2, int age) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.age = age;
}
void display() {
stroke(255);
if (age == 0) {
fill(0);
} else {
fill(255);
}
rectMode(CORNERS);
rect(x1, y1, x2, y2);
}
}
On the call to rect(), it gives me a null pointer.
Full error:
java.lang.NullPointerException
at sketch_161212a.draw(sketch_161212a.java:38)
at processing.core.PApplet.handleDraw(PApplet.java:2418)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:884)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)