Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting error "ArrayIndexOutofBound"

 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Problem is resolved.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Randall Twede
Ranch Hand
Posts: 4395
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I did it some different way. I really appreciated your help. Thanks once again.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote: . . . all that code . . .
What code?

Yatin Shah, you do not delete code after it has been replied to
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic