Results 1 to 4 of 4
- 02-04-2011, 07:21 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
Hi Guys,
I'm creating this program called CommandLineArguments out of this book. Its giving me the same error as before
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1".
This program is supposed to execute and output
args.length = 3
args[0] = 1
args[1] = 2
args[2] = abcde
when I type in "java CommandLineArguments 1 2 abcde" from the command line, but stops me and lets me know that I have an error. What am I missing? Here is my code.
public class CommandLineArguments {
public static void main(String[] args) {
System.out.println("args.length= " + args.length);
System.out.println("args[0]= " + args[0]);
System.out.println("args[1]= " + args[1]);
System.out.println("args[2]= " + args[2]);
}
}
- 02-04-2011, 08:10 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You sure you aren't adding any extra arguments on the command line by mistake? I just copy and pasted your code, compiled it, and supplied the args 1 2 abcde and got
as expected.Java Code:args.length= 3 args[0]= 1 args[1]= 2 args[2]= abcde
- 02-04-2011, 08:20 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
I am running it in eclipse and getting the error. Would that make a difference?
- 02-04-2011, 08:31 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By paul in forum New To JavaReplies: 8Last Post: 03-05-2011, 03:53 AM -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at wee
By Azaz in forum New To JavaReplies: 4Last Post: 02-02-2011, 04:32 AM -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 102
By dark_metal in forum New To JavaReplies: 5Last Post: 04-05-2010, 02:28 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks