Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ArrayList错误indexOutOfBoundsException_Android_Checkbox_Arraylist_Indexoutofboundsexception - Fatal编程技术网

Android ArrayList错误indexOutOfBoundsException

Android ArrayList错误indexOutOfBoundsException,android,checkbox,arraylist,indexoutofboundsexception,Android,Checkbox,Arraylist,Indexoutofboundsexception,我有一个带有复选框的列表视图,每当用户按下复选框时,我就会得到一些用户信息并存储在ArrayList中。取消选中该复选框时,用户信息将从arraylist中删除 现在的问题是,有时会出现错误: java.lang.IndexOutOfBoundsException: 如果未选中此复选框,则中的应用程序将停止 代码: 在您正在创建类似arraylist的pojo类中使用布尔类型变量。喜欢 布尔检查 然后为布尔变量生成getter setter 选中和取消选中UI上的复选框时。检查复选框是否选中,

我有一个带有复选框的列表视图,每当用户按下复选框时,我就会得到一些用户信息并存储在ArrayList中。取消选中该复选框时,用户信息将从arraylist中删除

现在的问题是,有时会出现错误:

java.lang.IndexOutOfBoundsException:
如果未选中此复选框,则中的应用程序将停止

代码:


在您正在创建类似arraylist的pojo类中使用布尔类型变量。喜欢 布尔检查

然后为布尔变量生成getter setter


选中和取消选中UI上的复选框时。检查复选框是否选中,并相应地设置布尔值。

是否可以发布适配器代码?发布一些相关代码。当遇到此类问题时,请确保发布代码块和Logcat。仅凭口头解释,在这里没有人能帮你。所以你得到了落选票!显示一些相关的代码。。。您可能没有正确设置循环。错误异常是正确的。相信它。
if (compoundButton.isChecked()) { 
       arrayList.get(arg0).setStatus(1); 
       barcode = arrayList.get(arg0).getBarcode(); 
       proprice = arrayList.get(arg0).getPrice();
       productname=arrayList.get(arg0).getItemName(); 
       Listbarcode.add(barcode + "," + productname + "," + proprice); 
} else { 
    if (Listbarcode.size() > 0){ 
        Listbarcode.remove(arg0); 
    } 
}