Look at the stack trace of the exception message. It tells you exactly in which line of code the exception happens. Then lookup that line in your code and find out why the exception happens there.
Note that if you have an array with N elements, then you can access the elements with the indices 0 to N-1.
This program expects an argument on the command line (which is passed to the main() method in the parameter 'args'). So when you run it, you must specify the parameter on the command line, for example: