I am trying to get the index of 466 in the arrayList minuteList
[288, 318, 346, 376, 406, 436, 466, 1006, 1036, 1066, 1096, 1126, 1156]
but I am getting this error:
java.lang.IndexOutOfBoundsException: Index: 466, Size: 13
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.pdf.PDF.refill_time_table(PDF.java:155)
at com.pdf.PDF.main(PDF.java:54)
I have debugged it and the minuteList has the values above as well the variable element has the value 466. How can I fix it?
I appreciate any help.
Code:
Collections.sort(diffArray);
int element = diffArray.get(diffArray.size() - 1).getElement();
int nextElement = diffArray.get(diffArray.size()-1).getNextElement();
//the error occur after this line.
minuteList.get(element);
minuteList.get(element); gives you the element whose index is element, which doesn't exist in your ArrayList (which only has 13 elements with indices from 0 to 12). Hence the IndexOutOfBoundsException.
You need minuteList.indexOf(element).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With