It's not a secret anymore!
The moose likes Java in General and the fly likes Getting error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting error "ArrayIndexOutofBound"" Watch "Getting error "ArrayIndexOutofBound"" New topic

Getting error "ArrayIndexOutofBound"

Yatin Shah
Ranch Hand

Joined: Sep 11, 2004
Posts: 72
My Problem is resolved.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20044

The exception comes from while ( (S[rightIndex] >= pivot) && ([rightIndex], pivot)>=0)). The reason is that you never check the bounds. Change both loops to make sure they don't go out of bounds:
This will get rid of the exception, although now there will be an infinite loop. I didn't check why tet.

The Comparator class should be made generic (using Number as bound wildcard), or use Integer as parameter types. That way you don't need to cast all these values. Also, Integer implements Comparable<Integer> so you can change your compare method to this:

How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347

rob, you are my hero. i sure don't have the patience to read through all that code to find the problem. unless i wrote myself that is

Visit my download page
Yatin Shah
Ranch Hand

Joined: Sep 11, 2004
Posts: 72
Thanks, I did it some different way. I really appreciated your help. Thanks once again.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43303
Randall Twede wrote: . . . all that code . . .
What code?

Yatin Shah, you do not delete code after it has been replied to
jQuery in Action, 3rd edition
subject: Getting error "ArrayIndexOutofBound"
It's not a secret anymore!