# Cannot find solution to: "Could not run the sketch (Target VM failed to initialize)"

**URL:** https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732
**Category:** Coding Questions
**Created:** [June 10, 2020, 9:53am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732 "2020-06-10T09:53:35Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)
#### Post date: [June 10, 2020, 9:53am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/1 "2020-06-10T09:53:35Z")

</div>

So I have been getting this error that is stated in the title and I have looked around a bit. The problem often seems to be a library or an nVidea driver however I am not using any nVidea drivers. So I am at a bit of a loss as of why I am getting this error. It only occurs in the code below.

```auto
ArrayList<PVector> Days = new ArrayList<PVector>(0);

int spread = 50;
int cols, rows;

void setup() {

  size(540, 960);

  cols = width/spread;
  rows = height/spread;

  for (int i = 0; i < cols; i++) {

    for (int j = 0; i < rows; j++) {

      int x = i * spread;
      int y = j * spread; 

      Days.add(new PVector(x, y));
    }
  }
}

void draw() {

  for (int i = Days.size() - 1; i >= 0; i--) {

    float x = ((PVector)Days.get(i)).x;
    float y = ((PVector)Days.get(i)).y;

    fill(255);
    stroke(0);
    ellipse(x, y, 50, 50);
  }
}

```

I am following the example here [http://learningprocessing.com/examples/chp16/example-16-06-Grid](http://learningprocessing.com/examples/chp16/example-16-06-Grid)  
and tried to adapt it for my own use, I am guessing something there went wrong.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2020, 10:04am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/2 "2020-06-10T10:04:03Z")

</div>

Restart your computer please

Sometimes only a hickup

---

<div class="post-metadata">

### Author: ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)
#### Post date: [June 10, 2020, 10:12am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/3 "2020-06-10T10:12:35Z")

</div>

This time I got a new error after running it for a little while  
“OutOfMemoryError: You may need to increase the memory settings in Prefrences”  
could this be because one of the loops didn’t stop looping? It highlighted line 20  
Days.add(new PVector(x, y));

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2020, 10:23am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/4 "2020-06-10T10:23:55Z")

</div>

> [@TheEternalDragon](#):
>
> ArrayList Days = new ArrayList(0);

Make This `ArrayList<PVector> Days = new ArrayList();`

Without 0 and with telling the Arraylist the type of its elements

---

<div class="post-metadata">

### Author: ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)
#### Post date: [June 10, 2020, 10:26am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/5 "2020-06-10T10:26:17Z")

</div>

Still gives me the same error sadly

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2020, 10:28am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/6 "2020-06-10T10:28:43Z")

</div>

> [@TheEternalDragon](#):
>
> `for (int j = 0; i < rows`

j \< rows NOT i \< rows

Computers are stupid

---

<div class="post-metadata">

### Author: ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)
#### Post date: [June 10, 2020, 10:30am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/7 "2020-06-10T10:30:33Z")

</div>

Jep I messed up making one of the loops, thanks for taking the time to sort that out for me 🙂

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2020, 10:35am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/8 "2020-06-10T10:35:25Z")

</div>

> [@TheEternalDragon](#):
>
> ```auto
> float x = ((PVector)Days.get(i)).x;
> float y = ((PVector)Days.get(i)).y;
> 
> ```

Technically:

`PVector pv = Days.get(i);`

(No need to tell (cast) PVector because you told it the Arraylist now when declaring it)

`ellipse(pv.x,pv.y, ......`

---

<div class="post-metadata">

### Author: ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)
#### Post date: [June 10, 2020, 10:39am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/9 "2020-06-10T10:39:37Z")

</div>

O yea true, thanks for the tip 🤔

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2020, 11:14am UTC](https://discourse.processing.org/t/cannot-find-solution-to-could-not-run-the-sketch-target-vm-failed-to-initialize/21732/10 "2020-06-10T11:14:01Z")

</div>

my version with comments

```auto

ArrayList<PVector> days = new ArrayList(); // lists start with lower case

void setup() {
  size(540, 960);

  int spread = 50; // make variables local when possible 
  int cols, rows;

  cols = width/spread;
  rows = height/spread;

  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      float x = i * spread + spread/2+18; // centering the grid 
      float y = j * spread + spread/2+5; 
      days.add(new PVector(x, y));
    }
  }
}

void draw() {
  fill(255);
  stroke(0);

  for (PVector pv : days) { // short form of for-loop 
    ellipse(pv.x, pv.y, 50, 50);
  }
}
//

```
