I've been coding for a few weeks now and I'm stuck on this null pointer exception.
It gives me the following error:
java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3768)
at processing.core.PApplet.image(PApplet.java:12175)
at beginfase.tekenBeginscherm(beginfase.java:126)
at beginfase.draw(beginfase.java:51)
at processing.core.PApplet.handleDraw(PApplet.java:2412)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1540)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
it marks this line of code: image(kaarten[r],50,50);
String[] kaart = {
"Aclubs.png",
"2clubs.png",
"3clubs.png",
"4clubs.png",
"5clubs.png",
"6clubs.png",
"7clubs.png",
"8clubs.png",
"9clubs.png",
"10clubs.png",
"Jclubs.png",
"Qclubs.png",
"Kclubs.png",
};
PImage[] kaarten = new PImage [kaart.length];
void settings() {
size(round(displayWidth * 0.9), round(displayHeight * 0.9));
}
void setup() {
laadBeginscherm();
// schudKaarten();
}
void draw() {
tekenBeginscherm();
// schudKaarten();
// println(mouseX);
//println(mouseY);
}
There is a bit of my code I know it's probably a mess and really bad, but I can't find what the nullpointerexception error is. Please help.
Yes, i now added the 10clubs.png
This is the code I use to load the image.
if (scherm == 3) {
background(0, 148, 0);
for (int g = 0; g < 12000; g = g+round((displayWidth * 0.9))/12) {
int r = int (random(kaarten.length));
println(r);
image(kaarten[r],g+25,50);
}
}
EDIT: Okay i made a smaller (mini) version of the error. It uses just 1 card but that's just for the example of it, so you can add a .png yourself
String[] kaart = {
"Aclubs.png",
};
PImage[] kaarten = new PImage [kaart.length];
void setup() {
kaart = loadImage("Aclubs.png");
}
void draw() {
tekenBeginscherm();
}
void tekenBeginscherm() {
if (keyPressed == true ) {
background(0, 148, 0);
for (int g = 0; g < 12000; g = g+round((displayWidth * 0.9))/12) {
int r = int (random(kaarten.length));
println(r);
image(kaarten[r], 50, 50);
}
}
}
If I try to add this: kaart = loadImage("Aclubs.png");
in setup()
The program will give me this error instead:
Type mismatch, "processing.core.PImage" does not match with "java.lang.String[]"