-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

2
  • 5
    Show us your code, and how are you executing it. How are you passing arguments currently? Commented Jan 24, 2013 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. Commented Jan 24, 2013 at 20:51

2 Answers 2

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]);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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

     }

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.