processing / processing

Source code for the Processing Core and Development Environment (PDE)

Home Page:http://processing.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array index out of bounds error using java-processing in terminal

hughrawlinson opened this issue · comments

Hi,

I keep getting the following error whenever I try and run any sketch:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at processing.app.Sketch.getCode(Sketch.java:1374)
    at processing.mode.java.Commander.statusError(Commander.java:319)
    at processing.mode.java.Commander.<init>(Commander.java:291)
    at processing.mode.java.Commander.main(Commander.java:97)
[Finished in 2.5s with exit code 1]
[cmd: ['processing-java', '--sketch=/Users/Hugh/Documents/Software Development/Processing/perception+multimedia+computing/week3lab/1', '--output=/Users/Hugh/Documents/Software Development/Processing/perception+multimedia+computing/week3lab/1/build-tmp', '--run', '--force']]
[dir: /Users/Hugh/Documents/Software Development/Processing/perception+multimedia+computing/week3lab/1]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

This happens when I'm not even using arrays with my code. I made sure it wasn't my code by testing with the following sketch:

void setup(){
  size(200,200);
}
void draw(){
  // do nothing
}

The weird thing is though, it works sporadically. When I was using it today in class, it worked fine. When I got home though, it started giving me this error.

Any help would be much appreciated. Thanks!

I just spend some time reading Commander.java and Sketch.java files, and what caught my attention is that you're using number 1 as your sketch folder

/Users/Hugh/Documents/Software Development/Processing/perception+multimedia+computing/week3lab/1

Sketch folders should have same name as sketches and sketches cannot have numerical names.
I wonder if this may be connected to your problem.
It can explain your sketch failing to run, but cannot explain that "it works sporadically"... maybe presence of other files in the directory or directory name can create some "coincidences" which may result in positive execution.

Nope, that totally explains it. It worked, then I changed the folder name, then before I ran it I went home, so I didn't connect changing the folder/sketch name with the fact that it stopped working. Is there any possibility of changing the requirement for names to be non-numerical? What is the reason that sketch names have to be non-numerical?

The requirement for sketches to have non-numerical names is fundamental. (Also since introduction of Android mode, they can neither start with underscore _ character).

The main reason for sketch names to have non-numerical names, is that your sketch 1.pde

void setup(){
  size(200,200);
}
void draw(){
  // do nothing
}

will be preprocessed (converted) into java source file:

import processing.core.*;
class 1 extends PApplet{
   void setup(){
      size(200,200);
   }
  void draw(){
    // do nothing
  }
}

and after that compiled with java compiler.

As you can see the name of the sketch is used as the name of the class. Java prohibits class names which start with numbers.

This is where fundamental nature of sketch names comes from.

Hope this helps, and I guess you may "close" the issue on github now.

Ok, I see. Thanks for your help.

It would be nice to throw a more understandable error though...

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.