# Could not run the sketch (Target VM failed to initialize)

**URL:** <https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [July 17, 2018, 4:03am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841 "2018-07-17T04:03:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkarlos4](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jkarlos4](https://discourse.processing.org/u/jkarlos4)\
**Post date:** [July 17, 2018, 4:03am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/1 "2018-07-17T04:03:00Z")

</div>

Help, I am getting this error message every time a run a code: Could not run the sketch (Target VM failed to initialize). have tried to run other included examples and they work pretty well, but not my code.  
here it is:

import processing.sound._;  
import processing.serial._;

SoundFile sample;  
FFT fft;  
AudioDevice device;

Serial myPort;

float[] spectrum =new float[3];  
float r, g, b;

float smoothing = 0.2;

public void setup() {  
size(640, 360); // Size of the serial window

device = new AudioDevice(this, 44000, 3);

sample = new SoundFile(this, “TwentyOnePilotsOdeToSleep.mp3”); // select your music here  
sample.loop();

fft = new FFT(this, 3);  
fft.input(sample);

myPort = new Serial (this, “COM3”, 9600); // Set the com port and the baud rate according to the Arduino IDE  
}

public void draw() {  
background(0, 0, 0);

fft.analyze();

spectrum[0] += (fft.spectrum[0] - spectrum[0]) \* smoothing;  
spectrum[1] += (fft.spectrum[1] - spectrum[1]) \* smoothing;  
spectrum[2] += (fft.spectrum[2] - spectrum[2]) \* smoothing;

r = spectrum[0]_height_4;  
g = spectrum[1]_height_4;  
b = spectrum[2]_height_4;

stroke(255,0,0);  
line( width/3 - 50, height, width/3 - 50, height - r );  
stroke(0,255,0);  
line( 2_width/3 - 50, height, 2_width/3 - 50, height - g);  
stroke(0,0,255);  
line( width - 50, height, width - 50, height - b );

```
myPort.write((int)r % 255);
myPort.write((int)g % 255);
myPort.write((int)b % 255);

```

}

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 17, 2018, 4:46am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/2 "2018-07-17T04:46:38Z")

</div>

Great you tested with some simpler files. I suggest you use the minim library for your project instead. As it is right now, the sound library is being revamped via a GSOC project. You might want to reach the current developers and comment about your problem or go ahead and use minim, which you can be installed via the Contribution Manager in the PDE.

> [@Early builds of the new Processing Sound library available for testing](https://discourse.processing.org/t/early-builds-of-the-new-processing-sound-library-available-for-testing/1796):
>
> Hello, as part of Google Summer of Code I’m currently doing a from-scratch rewrite of the Processing Sound library based on a Java sound synthesis engine, which should improve support for platforms such as Android and Raspberry Pi. The project has now progressed enough that I’m putting the first complete builds out to the public to test. If you’ve had troubles with the current Sound library, you might want to give this one a shot! I’ll put weekly-ish test releases up at this URL for the rest o…

Kf

---

<div class="post-metadata">

**Author:** ![jkarlos4](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jkarlos4](https://discourse.processing.org/u/jkarlos4)\
**Post date:** [July 17, 2018, 10:24pm UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/3 "2018-07-17T22:24:45Z")

</div>

Thank kfrajer. I will try with the minim library.

---

<div class="post-metadata">

**Author:** ![kevinstadler](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kevinstadler](https://discourse.processing.org/u/kevinstadler)\
**Post date:** [July 18, 2018, 10:11pm UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/4 "2018-07-18T22:11:55Z")

</div>

@jkarlos4, I think the problem is with

```auto
fft = new FFT(this, 3);

```

because the FFT’s size parameter can only be a power of 2 (i.e. 2, 4, 8, 16, 32,…). Even if it worked with an odd number such as 3, a spectral analysis on such few samples wouldn’t really give you meaningful results, it will mostly look like noise. Maybe try again with values of 64 or higher and take sums across the 64 values of `spectrum` to create the RGB values?

You can probably also remove the following line altogether, it’s not really necessary as long as your FFT size parameter isn’t greater than 128:

```auto
device = new AudioDevice(this, 44000, 3);

```

Let us know if it works!

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 19, 2018, 3:54am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/5 "2018-07-19T03:54:21Z")

</div>

I confirm, this is the error you get:

```auto
ERROR: /synth/map/input: Audio input index 0 out of range for synth 2
Could not run the sketch (Target VM failed to initialize).
Make sure that you haven't set the maximum available memory too high.
For more information, read revisions.txt and Help ? Troubleshooting.

```

when you set the buffer size to 3. I tried 64 and 512 and it worked (I commented out serial related lines).

Check previous FFT post if you want to see previous demos and their code.

Kf

---

<div class="post-metadata">

**Author:** ![jkarlos4](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jkarlos4](https://discourse.processing.org/u/jkarlos4)\
**Post date:** [July 21, 2018, 12:19am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/6 "2018-07-21T00:19:55Z")

</div>

This is a great community.  
Thanks Kfrajer and Kevinstadler for your help. I have tried by changing the values of the buffer size to 512, as you told me, and it work.

```auto
device = new AudioDevice(this, 44000, 512);
fft = new FFT(this, 512);

```

Now I got a decent RGB tape that light by music.

---

<div class="post-metadata">

**Author:** ![ubuntu-in-a-nutshell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ubuntu-in-a-nutshell/32/16992_2.png) [@ubuntu-in-a-nutshell](https://discourse.processing.org/u/ubuntu-in-a-nutshell)\
**Post date:** [October 5, 2021, 2:54am UTC](https://discourse.processing.org/t/could-not-run-the-sketch-target-vm-failed-to-initialize/1841/7 "2021-10-05T02:54:33Z")

</div>

I have got this error once. I don’t know why. It just seems like there is a random chance of it happening. (Processing 4 beta)
