Forum Stats

  • 3,837,108 Users
  • 2,262,226 Discussions
  • 7,900,204 Comments

Discussions

annoying arrayIndexOutOfBoundsException

Sepehr_DMV
Sepehr_DMV Member Posts: 1
edited Mar 14, 2020 1:24PM in Java Programming

hi , i have a annoying problem here on my first steps to code and to code in java , i wrote a simple insertion sort class and ran into this error so i wondered maybe something was wrong with the way i coded it so i copied a written code for it from geeksforgeeks and ran into the same error

(Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10

            at InsertionSort.sort(InsertionSort.java:6)

            at InsertionSort.main(InsertionSort.java:22) !

stack trace points to the same line (6 and 22 ) in both versions ! and Im using jdk 12 , compile and ran it with command line as well as IDE , so help here , are both codes wrong ? is it because it didn’t initialize the array using new inside the function ? or what ? thanks

heres the code i copied :

https://www.geeksforgeeks.org/insertion-sort/

T