IndexOutOfBoundsException with Android ArrayList

后端 未结 3 1179
误落风尘
误落风尘 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:54

    i

    You are looping past the last element in the array. Why the +1?

    If there are N elements in the array, then the elements are from indexes 0 through to N-1.

    So it should be:

    for(int i=0; i

提交回复
热议问题