IndexOutOfBoundsException with Android ArrayList

后端 未结 3 1180
误落风尘
误落风尘 2021-01-26 14:30

I\'ve got a very annoying problem with some code throwing an IndexOutOfBoundsException and I really cannot understand why. The logcat points to the \"addTimetableItem\" of the f

3条回答
  •  故里飘歌
    2021-01-26 14:46

    The last loop in your for loop runs:

    sortedFridayTimes.get(sortedFridayTimes.size())

    This will always be out of bounds, because the elements are zero indexed.

    For example, if the array size is "5", then you cannot access index "5", because the 5 elements in the array are 0,1,2,3,4.

提交回复
热议问题