This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 20078

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: 43935
Randall Twede wrote: . . . all that code . . .
What code?

Yatin Shah, you do not delete code after it has been replied to
I agree. Here's the link:
subject: Getting error "ArrayIndexOutofBound"
It's not a secret anymore!