• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Sohaib Sabir
Greenhorn
Posts: 3
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I tried to program Insertion-Sort algorithm but I got an error : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
How to solve it please

Asadun
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java array index starts from zero, not from one.
At some point in your code, you are trying to access a[6].
That is why the exception occurred.

Try to find in which part of the code you are trying to access a[6].
 
Sohaib Sabir
Greenhorn
Posts: 3
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

Here the solution, the error was in the i variable that have to start from index 0 and the condition in the while loop.

here is the final version :

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!