| Author |
Getting error "ArrayIndexOutofBound"
|
Yatin Shah
Ranch Hand
Joined: Sep 11, 2004
Posts: 72
|
|
|
My Problem is resolved.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
The exception comes from while ( (S[rightIndex] >= pivot) && (c.compare(S[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:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4089
|
|
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
|
SCJP
|
 |
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
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
Randall Twede wrote: . . . all that code . . .
What code?
Yatin Shah, you do not delete code after it has been replied to
|
 |
 |
|
|
subject: Getting error "ArrayIndexOutofBound"
|
|
|