NuLL Pointer Exception
in
Programming Questions
•
10 months ago
Hi guyz , I am new to processing and am trying to modify these code by storing the back ground image of each level in an array but it keeps giving me a Null pointer Exception please can anyone help me out in fixing these error.
int score=0;
int level=0;
int scoreMax=3;
int levelMax=5;
// used to store background colours - could store images in this way too
PImage[] backgrounds;
void setup() {
size(600, 440);
backgrounds = new PImage[6];
backgrounds[0]=loadImage("backround/level1bg.png");
backgrounds[1]=loadImage("background/guinea-fowls.png ");
backgrounds[2]=loadImage("background/level3bg.png");
backgrounds[3]=loadImage("backround/level1bg.png ");
backgrounds[4]=loadImage("background/guinea-fowls.png");
backgrounds[5]=loadImage("background/level3bg.png");
int txtSize=32;
PFont font = createFont("Arial", txtSize);
textFont(font,txtSize);
}
void draw() {
// background determined by current level
background(backgrounds[level]);
text("Score: "+ score, width/2, 50);
text("Level: "+ level, width/4,50);
if (level==levelMax && score ==scoreMax){
text("Game Over", 50, 150);
}
}
void keyPressed(){
// defines interactive behaviour of the game
// '+' key increases score up to scoreMax. When scoreMax reached, level increased.
if (key=='+'){
if(score < scoreMax){ score++;}
else if (level < levelMax){ score=0 ; level++; }
}
}
1