1. I have three classes
- Launcher........... (which launches 1 Parallel_Thread thread and 1 Shared Object)
- Parallel_thread.. (which talks twice to the shared object and then terminates)
- SharedObject.....(which runs until it is shut-down by the launcher class)
2. All Classes "javac" without any errors!
3. This is the Launcher Code
When running the launcher.class via java launcher<enter> from the commandline, this is the error that appears
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Launcher.main(Launcher.java:57)
Now my questions about this message? 1. How is it possible to get an ArrayIndexOutOfBoundsException error?
I do not enter any commandline arguments when starting this class, so the Args array is not being used.
2. How is it possible to get an error in LINE 57, while my Launcher.java sourcecode is only 33 lines???
This is really weird to me :~}
The error message you posted was thrown from line 57 of the Launcher class, in the main() method. But the code you posted for the Launcher class doesn't even have 57 lines. So the code you posted isn't the code which threw that exception. Fix that problem first.
posted 10 years ago
The story continues, At first here are all sourcecodes
3. Shared Object
4. Some diagnostic background info:
ronald@camelion:~/Desktop/java_exercisis/threads/a/example0_thread_templates> java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
5. Full error message after:
- removing all previous classfiles in the directory
- recompiling from the command-line with java /absolute/PATH/to/the/.java file
ronald@camelion:~/Desktop/java_exercisis/threads/a/example0_thread_templates> java Launcher
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
I am wondering if you get the same results (error), when compiling these source-codes?
Ulf Dittmer wrote:I concur with Paul's post: you're not running the code that you think you're running. When I compile and run the code I get this output:
THAT is the result i was searching for too Ulf! Thanks for the feedback and from running it on your own system.
UPDATE for all 1. I have searched my entire harddisk(s) and found NO second copy of Launcher.java and Launcher.class (not even in hidden directories, "recycle bin" or "Trash/files" directories.
2. I have removed all .class files from the working directory and recompiled the 3 sourcecodes again -> Same error!
3. Finally i found a "solution:"
- I renamed - the Launcher class to Ronald class (in line 1 of the Launcher.java file)
- I renamed - the file Launcher.java to Ronald.java
- I recompiled this Ronald.java example ..... en voila... error gone :-) so this problem is solved
4. It still keeps wondering/bugging me how it was possible that this error occurred? An error inline 57 of a 34 line sourecode.
Questions A - Is it possible that there is was another Launcher.java, Lancher.class file on my system -> No rule out that one by a disk search.
B - Does the JAVAC compiler itself store any old compilation results (class files) for possible re-use? or faster re-compilation
C - When I enter Javac <filename.java> HOW does JAVAC find the filename.java:
----- Does JAVAC search in the current directory first?
----- Does JAVAC search along the PATH of the computer it runs on?
----- Option 3?
Thank you all for your valuable feedback and explanation on this "error".