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.IndexOutOfBoundsException: Index: 1, Size: 1 when call refreshDotsSize() function #135

Closed
aprealian opened this issue Oct 19, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@aprealian
Copy link

aprealian commented Oct 19, 2021

For example we have 3 items in ViewPager2 adapter. This crash occurred when the last item is selected/opened then get new data and refresh the item.

Fatal Exception: java.lang.IndexOutOfBoundsException
Index: 1, Size: 1
com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator.refreshDotsSize (BaseDotsIndicator.kt:166)

in refreshDotsSize seems forgot to check the possibility of index out of bound

private fun refreshDotsSize() {
for (i in 0 until pager!!.currentItem) {
dots[i].setWidth(dotsSize.toInt())
}
}

maybe you can edit and change it into

private fun refreshDotsSize() {
for (i in 0 until pager!!.currentItem) {
if (i < dots.size){
dots[i].setWidth(dotsSize.toInt())
}
}
}

@Maradox
Copy link

Maradox commented Nov 16, 2021

I get similar crashlogs for Index: 0, Size: 0.

Fatal Exception: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) at com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator.refreshDotsSize(BaseDotsIndicator.java:166) at com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator.access$refreshDotsSize(BaseDotsIndicator.java:20) at com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator$refreshDots$1.run(BaseDotsIndicator.java:150) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:247) at android.app.ActivityThread.main(ActivityThread.java:8656) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

@Ba1Dan
Copy link

Ba1Dan commented Mar 9, 2022

How to solved this issue?

@tommybuonomo tommybuonomo self-assigned this Apr 30, 2022
@tommybuonomo tommybuonomo added this to the 4.3 milestone Apr 30, 2022
@tommybuonomo
Copy link
Owner

Hello, thanks for your contribution !
This issue is now fixed in the new version 4.3
Thanks 🔥

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

No branches or pull requests

4 participants