【发布时间】:2020-04-14 14:43:35
【问题描述】:
我尝试在未选中时从地图中删除一个值,但由于某种原因,它给了我一个 IndexOutOfBoundsException
itemView.checkBox.setOnCheckedChangeListener { buttonView, isChecked ->
item.isChecked = isChecked
if(isChecked){
map.put(position,true)
} else {
map.removeAt(position)
}
}
这里我有 2 个复选框,当我检查两个都可以时。当我取消选中第一个是可以的,但是当我尝试取消选中第二个时,它会因为这个错误而崩溃
java.lang.ArrayIndexOutOfBoundsException: src.length=11 srcPos=2 dst.length=11 dstPos=1 length=-1
问题出在map.removeAt(position),但我不知道它为什么会失败,因为该位置是数组中实际存在的元素。
我正在使用SparseBooleanArray。
【问题讨论】:
标签: java android arrays kotlin android-recyclerview