• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7  RSS feed

 
paul a carron
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a Quicksort example from the book Java: A Beginners Guide(5th edition):



Maybe I've been looking at it for so long now that I'm missing the obvious but I can't understand why I get the below error:
Original array: dxarpji
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at Quicksort.qs(Quicksort.java:22)
at Quicksort.qsort(Quicksort.java:6)
at QSDemo.main(QSDemo.java:16)


Can anybody please advise?
 
Norman Radder
Ranch Hand
Posts: 146
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at Quicksort.qs(Quicksort.java:22) 

At line 22 the program used an index (7) past the end of the array.  Remember array indexes range in value from 0 to the array's length-1.
Make sure the index values stay in range.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at line 30.
 
paul a carron
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks guys. I think I was right about missing the obvious from looking at it too much. I actually thought I had checked for j--;. It seems I can't even copy today!

It's working now.

Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!