Identical code works in processing IDE, but not from vscode/CLI

I was going through this example from the website: Array 2D / Examples / Processing.org and I had no problem running it with the pre-built processing IDE. The file can also be run using CLI once saved to sketchbook.

adam@gandalf:~/sketchbook/practice$ processing-java --sketch=./sketch_2d_arrays_test --run
Finished.

However, when I manually create a .pde file, edit it in vscode, paste in identical code from the link above and try to run it from CLI, I get this error:

adam@gandalf:~/sketchbook/practice$ processing-java --sketch=./2d_array_test_vscode --run
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at processing.app.Sketch.getMainName(Sketch.java:1699)
	at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:144)
	at processing.mode.java.JavaBuild.build(JavaBuild.java:110)
	at processing.mode.java.Commander.<init>(Commander.java:233)
	at processing.mode.java.Commander.main(Commander.java:417)

Is there a step that I’m missing here? Both files contain exactly the same code, the only difference being that I created one manually, while the other was created and saved out using the Processing IDE.

I think I’ve figured out the issue! Turns out this error will occur if you start the name of the sketch with a number. The processing IDE automatically adds the sketch_ prefix to sketches that you save, which is why the error happened when I used vscode, but not when I used the IDE.

3 Likes