Hello everyone, I am writing a game using processing in Eclipse, but I get a strange NullPointerException error when using pushMatrix in two of my classes. Even taking out the pushMatrix() and popMatrix() doesn’t work, causing the program to throw the error at translate(). I cannot figure out what the error is. What is causing the error to occur?
Here is the code:
import processing.core.*;
public class Face extends PApplet {
float x1;
float x2;
float y1;
float y2;
float z1;
float z2;
float size;
boolean isFront, isBack, isRight, isLeft, isTop, isBottom;
int col;
PVector position;
boolean wireframe;
boolean switchTexture;
public Face (float s) {
x1 = -s/2;
x2 = s/2;
y1 = -s/2;
y2 = s/2;
z1 = -s/2;
z2 = s/2;
size = s;
isFront = false;
isRight = false;
isBack = false;
isLeft = false;
isTop = false;
isBottom = false;
wireframe = false;
switchTexture = false;
}
public void display() {
pushMatrix();
translate(position.x, position.y, position.z);
beginShape();
if (!wireframe) {
noStroke();
} else {
stroke(0);
noFill();
noTexture();
}
texture(Game.grass3);
if (isFront) {
vertex(x1, y1, z1, 0, 0);
vertex(x2, y1, z1, size/2, 0);
vertex(x2, y2, z1, size/2, size/2);
vertex(x1, y2, z1, 0, size/2);
}
if (isRight) {
vertex(x2, y1, z1, 0, 0);
vertex(x2, y1, z2, size/2, 0);
vertex(x2, y2, z2, size/2, size/2);
vertex(x2, y2, z1, 0, size/2);
}
if (isBack) {
vertex(x2, y1, z2, 0, 0);
vertex(x1, y1, z2, size/2, 0);
vertex(x1, y2, z2, size/2, size/2);
vertex(x2, y2, z2, 0, size/2);
}
if (isLeft) {
vertex(x1, y1, z2, 0, 0);
vertex(x1, y1, z1, size/2, 0);
vertex(x1, y2, z1, size/2, size/2);
vertex(x1, y2, z2, 0, size/2);
}
if (isTop) {
texture(Game.grass2);
vertex(x1, y1, z2, 0, 0);
vertex(x2, y1, z2, size/2, 0);
vertex(x2, y1, z1, size/2, size/2);
vertex(x1, y1, z1, 0, size/2);
}
if (isBottom) {
vertex(x1, y2, z1, 0, 0);
vertex(x2, y2, z1, size/2, 0);
vertex(x2, y2, z2, size/2, size/2);
vertex(x1, y2, z2, 0, size/2);
}
endShape();
popMatrix();
}
}
Note: the game class, “Game” is the class in which I make the PApplet.