| Author |
Exception in thread
|
Michael Statham
Greenhorn
Joined: Feb 11, 2007
Posts: 1
|
|
I've written this code so far and only 1 error but it's driving me nuts, maybe lack of sleep or something far worse, who knows. If any one can help, thank you in advance. This is the error I'm getting any help would be appreciated in advance, thank you! Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at QuickSort.main(QuickSort.java:77)
|
Mike
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
How are you running it? I ran it using this command and this was my output:
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Anton Uwe
Ranch Hand
Joined: Jan 10, 2007
Posts: 122
|
|
|
Perhaps you called this program without a parameter?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Welcome to the Ranch. Go back to your Exception error message; it has a line no on ?77. Go to your line 77 and there you will find an array used. If the index is 0 it means you don't have a 1st member. There are several possibilities for this error:-1: You have an array declared but have never created it with a statement like: fooArray = new foo[20];2: You have an array which you have never inserted any members into.Are you using the args[] array without passing anything from the command line? That is a potent source of unexpected ArrayIndexEtcExceptions. CR [ February 11, 2007: Message edited by: Campbell Ritchie ]
|
 |
kiranmayi srivastava
Greenhorn
Joined: Feb 12, 2007
Posts: 1
|
|
I think the error comes when there is no argument passed with the run command. This can be handled this way: Replace int N = Integer.parseInt(args[0]); with the following code: int N = 0; if(args.length > 0) N = Integer.parseInt(args[0]); OR int N = 0; try { N = Integer.parseInt(args[0]); } catch (ArrayIndexOutOfBoundsException aiob) { System.out.println("No value recieved!!!"); }
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Campbell Ritchie: There are several possibilities for this error:- 1: You have an array declared but have never created it with a statement like: fooArray = new foo[20];2: You have an array which you have never inserted any members into.
Not quite - the first would cause a NullPointerException when trying to access the array, the latter doesn't make sense to me because you don't really *insert* members to arrays. Really the only way this error can happen is when the array has a length of zero.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: Exception in thread
|
|
|