2

I am trying to pass parameter to a java class main method I want to pass parameter using eclipse so I went to

run -> run configuration -> program arguments

and I wrote my arguments

exp grammar

But whenever I run it gives me this error,

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at LL.main(LL.java:146)

Which means it does not see the second argument "grammar", anyone know why and how to solve this ?


edit , here is my main method

public static void main(String[] args) throws IOException {
    String exp = args[0] + '$';
    LL input = new LL(exp, Grammar.fromFile(args[1]));
    try {
        input.lLParse();
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}
Alex Salauyou
  • 14,185
  • 5
  • 45
  • 67
Halawa
  • 1,171
  • 2
  • 9
  • 19
  • @Suspended: That's the main method that's already posted in the question. – Makoto May 12 '15 at 04:11
  • does the program run successfully when you call `java LL exp grammar` from command line? – Prasad Kharkar May 12 '15 at 04:14
  • it is gives the same error from command line although i am giving input of two strings but the error indicates it sees only one . – Halawa May 12 '15 at 04:20
  • 1
    Could you System.out.println() each of your arguments and confirm that they are both being read? – shinjw May 12 '15 at 04:26
  • first argument exp is printed correctly which is args[0] the problem is with the grammar as my main cannot see args[1] although i am passing 2 strings . and by the way i cannot print the grammar – Halawa May 12 '15 at 04:44

4 Answers4

2

In Run -> Run Configuration -> Java Application -> Arguments enter inputs separating by space

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
1

1)Right-click on Main class

2)Click on 'Run As'

3)Click on 'Run Configurations...'

4)Click on 'Arguments'

5)Enter input in 'Program Arguments' section

6)Click on 'Apply' and 'Run'

Note - for multiple inputs, you can enter multiple inputs in different lines in 'Program argument section'

Vijay
  • 4,694
  • 1
  • 30
  • 38
0

Check for extra space between this two arguments

Moosa
  • 79
  • 1
  • 2
  • 12
-1

"ArrayIndexOutOfBoundsException"

Try extending the index for array exp to args.length

0x2B
  • 91
  • 9
  • Sorry didn't see that. try doing this for (int i = 0; i < args.length; i++) System.out.println(args[i]); } – 0x2B May 12 '15 at 05:05