brucetoo/PickView

java.lang.ArrayIndexOutOfBoundsException: at ... at com.bruce.pickerview.LoopView.onDraw(LoopView.java:258) #81

odufuwa-segun opened this issue · 1 comments

java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
at java.util.ArrayList.get(ArrayList.java:310)
at com.bruce.pickerview.LoopView.onDraw(LoopView.java:258)

The issue is cause by the looping
if (templateItem < 0) {
templateItem = templateItem + mDataList.size();
}
if (templateItem > mDataList.size() - 1) {
templateItem = templateItem - mDataList.size();
}
// at this point the templateItem could still be a negative number if the items are really small say 2 and the number of items to be displayed is say 10, for the templateItem to be positive this would need to be looped 5 times.
itemCount[count] = (String) mDataList.get(templateItem);

// i fixed the error by adding
// if (templateItem < 0) continue; just before the itemCount[count] = ...

//It should be corrected as
if (templateItem < 0) continue; // to prevent futher looping after the first loop
itemCount[count] = (String) mDataList.get(templateItem);

This lib needs big improvement if i have time.