[Solved] ArrayIndexOutOfBoundsException when accessing args [closed]


You receive this error message because the length of the args array is shorter that the position you are tring to access. As the other answers have mentioned, you may not be sending the command line arguments, or you may be sending only one, and when you try to access the second one (args[1]) you receive Array index out of bounds exception.

The best thing you can do, is check for the length of the array before you access the values, or even iterating inside a for instruction until the length of the array is reached.

Use this instruction to print the values:

for(int i=0; i< arr.length;i++)
{
    System.out.print(Double.parseDouble(args[i]));
}

And if it does not show anythng is because you are not passing the arguments to the program.

3

solved ArrayIndexOutOfBoundsException when accessing args [closed]