Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
odufuwa-segun opened this issue Feb 20, 2017 · 1 comment

Comments

@odufuwa-segun
Copy link

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);

@brucetoo
Copy link
Owner

This lib needs big improvement if i have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants