• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 146
4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at line 30.
 
paul a carron
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic