I’m currently trying to create a game for my computer science class and I’m having a bit of a rocky start, to be honest. What I have below is the basis of the game but I’m running into a problem when I run the code. It displays an error saying “NUllPointerException” and then highlights this line of code: “image(standingImages[int(frame)], link[0], link[1]);” I’m hoping to not change any of the code to new things I haven’t done before, as I’m a beginner and I can’t show my teacher code that has things we’ve never done before. If anyone would be willing to help, it would be greatly appreciated! thank you! (See Code Below)
PImage[] rightImages=new PImage[6];
PImage[] leftImages=new PImage[6];
PImage[] standingImages=new PImage[6];//*********************
Float frame=0.0;
//x y for link
int[] link={80, 110};
boolean[] keys=new boolean[128];
boolean moveRight=false;
boolean moveLeft=false;
boolean stand=false;//*********************
void setup() {
size(300, 300);
frameRate(60);
//loading all "standing" images
for (int i=1; i<standingImages.length; i++) {//***************************
standingImages[i]=loadImage("link stand "+(i)+".png");
}
//loading all "right" images
for (int i=1; i<rightImages.length; i++) {
rightImages[i]=loadImage("linkright"+(i)+".png");
}
//loading all "left" images
for (int i=1; i<leftImages.length; i++) {
leftImages[i]=loadImage("linkleft"+(i)+".png");
}
}//end setup
void draw() {
background(200, 80, 50);
moveLink();
if (moveRight) {
image(rightImages[int(frame)], link[0], link[1]);
}
else if (moveLeft) {
image(leftImages[int(frame)], link[0], link[1]);
}
else if (stand) {//******************************************
image(standingImages[int(frame)], link[0], link[1]);
}
frame+=0.1;
if (frame>6) {
frame=1.0;
}
}//end draw
void moveLink() {
if (keys[65]) {//65 is 'a' - move left
link[0]-=3;
moveLeft=true;
} else{
moveLeft=false;
}
if (keys[68]) {//68 is 'd' - move right
link[0]+=3;
moveRight=true;
} else {
moveRight=false;
}
if (keys[65]==false && keys[68]==false){//******************************
stand=true;
}
}//end moveLink
void keyPressed() {
keys[keyCode]=true;
}
void keyReleased() {
keys[keyCode]=false;
}