• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Please help me...

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code.



Whats wrong with this?Thank you.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Chaturaka Gunatilaka wrote:Whats wrong with this?Thank you.


What makes you think there is something wrong with it ? TellTheDetails
 
Chaturaka Gunatilaka
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stuart A. Burkett wrote:

Chaturaka Gunatilaka wrote:Whats wrong with this?Thank you.


What makes you think there is something wrong with it ? TellTheDetails



There is an out of bound exception.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Chaturaka Gunatilaka wrote:There is an out of bound exception.


Where ? TellTheDetails - read this link carefully before posting again.
 
Chaturaka Gunatilaka
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error

Sorted values :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at sort.partition(sort.java:11)
at quickSort.main(quickSort.java:6)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please UseAMeaningfulSubjectLine instead of "Please help me" when you post a question.

ArrayIndexOutOfBoundsException means that you're trying to access an array using an invalid index. If the length of the array is N, then 0 upto and including N - 1 are valid indices.

Read the error message carefully. It tells you exactly in which line the error occurs. Carefully analyze your program to see what happens. Add some System.out.println(...) statements to print out useful information, to help you understand what's happening. You could also run the code using a debugger, so that you can step through the code line by line while it runs, which might help you understand what happens exactly.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more point... The partition(...) method should be used internally by method that actually implements the algorithm (if you really want Quicksort) and not invoked separately from main. So I would make that one private and change the implementation accordingly.
 
lowercase baba
Posts: 12751
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can always stick in System.out.println() statements to see what your code is doing. Whichever line is throwing the error, print out what index you are trying to reference. You will probably see you are trying to access index n on an array that has n elements. Since you can only use indexes 0 through n - 1, using n give an out of bounds exception.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!