tommybuonomo / dotsindicator

Three material Dots Indicators for view pagers in Android !

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

aprealian opened this issue · comments

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())
}
}
}

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)

How to solved this issue?

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