Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

annoying arrayIndexOutOfBoundsException

Sepehr_DMVMar 14 2020 — edited Mar 14 2020

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

Comments
Post Details
Added on Mar 14 2020
0 comments
307 views