Skip to content

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

@aprealian

Description

@aprealian

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions