-2

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

Community
  • 1
  • 1
Arnold Parge
  • 6,684
  • 2
  • 30
  • 34
  • 5
    Show us your code, and how are you executing it. How are you passing arguments currently? – Rohit Jain Jan 24 '13 at 20:46
  • You probably run your program from Eclipse or other debugger, where you should explicitly set all arguments in run configuration, including zero one. – Suzan Cioc Jan 24 '13 at 20:51

2 Answers2

2

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]);
    }
}
Grambot
  • 4,370
  • 5
  • 28
  • 43
1

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")

     }

}
Mechkov
  • 4,294
  • 1
  • 17
  • 25