aspose file tools*
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
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: 19760
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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
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
Sheriff

Joined: Oct 13, 2005
Posts: 39815
    
  28
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: http://aspose.com/file-tools
 
subject: Getting error "ArrayIndexOutofBound"