tommybuonomo / dotsindicator

Three material Dots Indicators for view pagers in Android !
Apache License 2.0
3.44k stars 353 forks source link

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 when call refreshDotsSize() function #135

Closed aprealian closed 2 years ago

aprealian commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

How to solved this issue?

tommybuonomo commented 2 years ago

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