1
ConcurrentModificationException的我試圖從數組列表中刪除項目,但拋出ConcurrentModificationException的如何避免ArrayList中
listIterator = CustomListArr.iterator();
for (ClassA value : CustomListArr) {
try {
String query = "SELECT * FROM DEVICE_INFO WHERE DEV_IP='" + value.getaddress() + "'";
String address = value.getiip();
SQLiteDatabase db = dbController.getReadableDatabase();
Cursor cursor1 = db.rawQuery(query, null);
if (cursor1 != null) {
if (cursor1.moveToFirst()) {
do {
while (listIterator.hasNext()) {
String ss = listIterator.next().getiip();
if (ss.equals(ippaddress)) {
listIterator.remove();
} else {
System.out.println(ss);
}
}
CustomHotspotListArr.size();
} while (cursor1.moveToNext());
}
}
} catch (Exception e) {
String error = e.toString();
}
}
if (CustomListArr.size() > 1) {
list_adapter_configure = new CustomListview(Conf_devicelist.this, R.layout.conf_items, CustomListArr);
lv_configrue.setAdapter(list_adapter_configure);
} else if (CustomListArr.size() == 1) {
startActivity(new Intent(getApplicationContext(), New_Activity.class));
finish();
} else if (CustomListArr.size() == 0){
Toast.makeText(Conf_devicelist.this, "No New Device Found", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
感謝您的回答。在CustomListArr中使用CopyOnWriteArrayList後,異常被清除。 –