How are you running this program? It expects you to supply two numbers on the command line when you run it. You should for example type in a command like this:
go to project explorer and select your project , right click on it and you will find
Run as->Run configurations->arguments -> program arguments
provide your values in the window shown, be careful to put a space between your values , apply and run
That's it !
Sakthi velan
Greenhorn
Joined: May 12, 2011
Posts: 3
posted
0
Thanks a lot. It worked.
umesh mahato
Greenhorn
Joined: Nov 19, 2012
Posts: 1
posted
0
i'm using netbeans ide 7.3 beta for java programming. i'll be grateful to anyone there who could help me with the same error in netbeans.
Wesleigh Pieters
Ranch Hand
Joined: Sep 04, 2012
Posts: 81
posted
0
umesh mahato wrote:i'm using netbeans ide 7.3 beta for java programming. i'll be grateful to anyone there who could help me with the same error in netbeans.
if you right click the project and select properties, under the run options there is arguments.
Abid Ramay
Greenhorn
Joined: Apr 06, 2013
Posts: 17
posted
0
@Jesper de Jong
your suggestin worked but can't make no sense .. if you point in the direction will be helpfull ..
your suggestin worked but can't make no sense .. if you point in the direction will be helpfull ..
He explained it pretty clearly. What don't you understand?
Abid Ramay
Greenhorn
Joined: Apr 06, 2013
Posts: 17
posted
0
i am not using IDE .. just text editor .. i meant some theory to help understand the problem.
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 321
posted
1
Abid Ramay wrote:i meant some theory to help understand the problem.
The problem was that if you don't pass any command line arguments to a program, the args array that is a parameter to the main method will not contain any values - it will be a zero lenghth array.
On line 13 of the program an attempt was made to access the first element of the array. Because the array has no elements, this isn't possible so the program throws an ArrayIndexOutOfBoundsException.
In general, if an array has size n, you can only access elements with indexes less than n and positive
e.g.
If you have an array of size 3, you can access elements 0, 1 and 2