Java ConcurrentModificationException With Custom Array list

时间:2016-03-05 03:40:19

标签: android exception concurrentmodification

 @Override
 protected void publishResults(CharSequence constraint, FilterResults results) {
            ArrayList<DrugsInfo> filteredList = (ArrayList<DrugsInfo>) results.values;
            if(results != null && results.count > 0) {
                clear();
                for (DrugsInfo c : filteredList) {
                    add(c);
                }
                notifyDataSetChanged();
            }
        }
    };

我在这里得到一个Concurrent Modification异常.Plz建议如何解决..

1 个答案:

答案 0 :(得分:0)

因此,您需要使用迭代器(因为我无法看到整个代码):

for (Iterator<DrugsInfo> it = filteredList.iterator(); it.hasNext(); ) {
    DrugsInfo c = it.next();
    add(c)
}