-1

I'm putting together code for sorting algorithms. It's meant to demonstrate the fastest method between different types of data sets. So far it compiles but I continue to receive the following error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at SortTestPractice.insertionSorty(SortTestPractice.java:152)
    at SortTestPractice.testSpeed(SortTestPractice.java:71)
    at SortTestPractice.main(SortTestPractice.java:17

What does this error mean and what can I do to rectify this?

  • *insertionSort there's no syntax error – Ryan Schubert Sep 20 '17 at 00:56
  • Have you tried, you know, googling a "ArrayIndexOutOfBoundsException"? https://www.google.ca/search?q=java+what+is+array+index+out+of+bounds+exception&oq=java+what+is+array+index+out+of+bounds+exception+&aqs=chrome..69i57j0l5.8152j0j7&sourceid=chrome&ie=UTF-8 – aphrid Sep 20 '17 at 00:59
  • It means there is a bug in your code at `SortTestPractice.java` line 152. Without posting your code, no-one can help you any further. – Ken Y-N Sep 20 '17 at 01:00

2 Answers2

0

ArrayIndexOutOfBoundsException means that your program is trying to access data out of bounds of the array. That is, the program is outside of the declared memory for its scope. Look at where you access arrays or ArrayList and you will find that the program is trying to manipulate data which is outside of the declared array or list.

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0

ArrayIndexOutOfBoundsException: -1

Meaning: your code is trying to access the array element with index -1

It's very likely that you have a logical error at SortTestPractice.insertionSorty(SortTestPractice.java:152)