Possible Duplicate:
What is “String args[]”? in Java
How do you accept values using command line argument in java? Whenever I try to do it, it shows
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
Possible Duplicate:
What is “String args[]”? in Java
How do you accept values using command line argument in java? Whenever I try to do it, it shows
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
What have you tried? See this block for how to access the args
array. You'll need to provide more details for why you're getting outofbounds exception, otherwise use this as a template.
public static void main(String args[]) {
for (int i = 0; i < args.length; i++) {
System.out.println("Argument #" + i + " = " + args[i]);
}
}
from command line:
java MyApp firstParameter secondParameter
In your app;
public static void main(String[] argv) {
for(String parameter: argv) {
System.out.println(parameter + "\n")
}
}