# Error in Processing program

**URL:** https://discourse.processing.org/t/error-in-processing-program/6587
**Category:** Coding Questions
**Created:** [December 14, 2018, 2:33am UTC](https://discourse.processing.org/t/error-in-processing-program/6587 "2018-12-14T02:33:09Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Smithy](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Smithy](https://discourse.processing.org/u/Smithy)
#### Post date: [December 14, 2018, 2:33am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/1 "2018-12-14T02:33:09Z")

</div>

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:

```auto
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:

```auto
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:

```auto
Globalcards[i].display();

```

I would be grateful for any suggestions or help provided. Thanks.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 14, 2018, 2:37am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/2 "2018-12-14T02:37:28Z")

</div>

you need to make ALL the cards you want use later FIRST

```auto
 for(int i = 1; i<12; i++){
    Globalcards[i] = new Cards (x[i], y[i], f[i]);
  }

```

not fit to

```auto
for(int i = 0; i<12; i++){
    Globalcards[i].display();
  }

```

so Globalcards[0] is missing

//\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
sorry, you edit the title at the same time

> Error in Processing program,if you are a genius - come prove it 🙂

i never think i am a genius like you

---

<div class="post-metadata">

### Author: ![Smithy](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Smithy](https://discourse.processing.org/u/Smithy)
#### Post date: [December 14, 2018, 2:40am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/3 "2018-12-14T02:40:38Z")

</div>

Thanks for the reply, i don’t quite understand what you mean… could you please elaborate.

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [December 14, 2018, 2:43am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/4 "2018-12-14T02:43:43Z")

</div>

You never set `Globalcards[0]` to be anything!

You have this loop in `setup()`:

```auto
  for(int i = 1; i<12; i++){
    Globalcards[i] = new Cards (x[i], y[i], f[i]);
  }

```

When you actually need this loop:

```auto
  for(int i = 0; i<12; i++){
    Globalcards[i] = new Cards (x[i], y[i], f[i]);
  }

```

Notice that the 1 becomes a 0. This minor change ensures that, in this loop, `Globalcards[0]` is also assigned to be something.

---

<div class="post-metadata">

### Author: ![Smithy](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Smithy](https://discourse.processing.org/u/Smithy)
#### Post date: [December 14, 2018, 2:47am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/5 "2018-12-14T02:47:08Z")

</div>

Thanks so much, the the code now actually runs. though i realised one of my pictures is way too big… so its covering the whole screen 😮

---

<div class="post-metadata">

### Author: ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)
#### Post date: [December 14, 2018, 5:43am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/6 "2018-12-14T05:43:35Z")

</div>

HI @Smithy, can you repost your question please? it seems like there was an error when you edited your post

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [December 14, 2018, 9:41am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/7 "2018-12-14T09:41:49Z")

</div>

@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. 😁

Perhaps a moderator can restore the original.

---

<div class="post-metadata">

### Author: ![JulietteP](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/juliettep/32/2800_2.png) [@JulietteP](https://discourse.processing.org/u/JulietteP)
#### Post date: [December 14, 2018, 10:04am UTC](https://discourse.processing.org/t/error-in-processing-program/6587/8 "2018-12-14T10:04:31Z")

</div>

Why would someone deliberately destroy his question ? I don’t get it.

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [December 14, 2018, 2:59pm UTC](https://discourse.processing.org/t/error-in-processing-program/6587/9 "2018-12-14T14:59:01Z")

</div>

Maybe it is an assignment and OP doesn’t want his/her teacher to notice the post.

I’m happy you have geniuses here on the forum 🙂

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [December 14, 2018, 5:05pm UTC](https://discourse.processing.org/t/error-in-processing-program/6587/10 "2018-12-14T17:05:53Z")

</div>

> [@quark](#):
>
> Perhaps a moderator can restore the original.

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.
