Error in Processing program
Error in Processing program, if you are a genius - come prove it
Hi everyone, i am currently creating a game in which i have encountered a problem. My sketch isn’t able to run, and i have no idea why. I get the NullPointerEception when trying to run my sketch. When force quitting the java start-up program, my console shows this “Could not run the sketch (Target VM failed to initialise).” By the way, the game i am trying to create is a picture memory game.
Here is my code:
Cards[] Globalcards = new Cards[12];
int[] x= new int[12];
int[] y = new int[12];
int[] f = new int[12];
void setup() {
int myX = 40;
int myY = 40;
size(500,500);
for(int i = 0; i<12; i++){
x[i] = myX;
y[i] = myY;
f[i] = i + 1;
if (myX<390){
myX += 100;
}
else if (myX>390){
myX = 40;
myY += 120;
}
}
shuffle();
for(int i = 1; i<12; i++){
Globalcards[i] = new Cards (x[i], y[i], f[i]);
}
}
void draw() {
for(int i = 0; i<12; i++){
Globalcards[i].display();
}
if (mousePressed){
flipme();
}
}
void flipme(){
for(int i = 0; i<12; i++){
if (mouseX > x[i] && mouseX<(x[i]+50) && mouseY>(y[i]+120)){
Globalcards[i].displayFront();
}
}
}
void shuffle(){
int z = 0;
int u = 0;
for (int i = 0; i<12; i++){
u = int(random(0,12));
z = f[i];
f[i] = f[u];
f[u] = z;
}
}
Here is also the class Cards code i am running with it:
class Cards {
PImage cardImage;
int show = 0;
int cardX = 0;
int cardY = 0;
int face = 0;
String[] cardTheme = {"japan_style_elements_vector_graphics.png", "e7ca329b9c.png", "83c5bf9c8b.png", "83c5bfa28b.png", "605210998b.png", "83c5bfa48b.png" };
Cards(int x, int y, int f){
cardX = x;
cardY = y;
face = f;
}
void display(){
cardImage = loadImage(cardTheme[show]);
image(cardImage, cardX, cardY);
}
void displayFront(){
show = face;
}
}
Finally i have noticed that the program highlights this specific line when it fails to run:
Globalcards[i].display();
I would be grateful for any suggestions or help provided. Thanks.
@Smithy has made 3 edits and I suspect he has deliberately destroyed the question. We used to get this a lot on the old forum but this one is nice, click on the pencil in his post and you can see the original question.
I have restored the post and locked it from future edits. @Smithy
Self-vandalism – especially after forum members have contributed public answers to a public question – is against forum policy. People answer for the good of all, and self-vandalism makes those answers impossible to understand. Self-vandalism also supports cheating on classwork, and this forum does not support cheating – advice should be incorporated into student work in a way that does not need to be a secret. If you want to remove a post with no substantial answers – or if you have a concern about privacy – please flag your post for help from a moderator.