Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hughrawlinson opened this issue Oct 19, 2013 · 6 comments
Closed

Comments

@hughrawlinson
Copy link

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!

@dimkir
Copy link

dimkir commented Oct 19, 2013

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.

@hughrawlinson
Copy link
Author

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?

@dimkir
Copy link

dimkir commented Oct 19, 2013

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.

@hughrawlinson
Copy link
Author

Ok, I see. Thanks for your help.

@hughrawlinson
Copy link
Author

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

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants