球球好心人康康,实在是没辙了,本人小菜鸟,公司就我一个安卓开发,也没人可问。
HashMap遍历删除写在方法内的一个线程里:
new Thread(new Runnable() {
@Override
public void run() {
Iterator iterator = three.keySet().iterator();
while (iterator.hasNext()) {
…
iterator.remove();
three.remove(key); //这行代码
}
}
}
}).start();
报错信息:
E/AndroidRuntime: FATAL EXCEPTION: Thread-1317
Process: com.example.administrator.i, PID: 4777
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.remove(HashMap.java:869)
at com.example.administrator.i.MainActivity$12.run(MainActivity.java:911)
at java.lang.Thread.run(Thread.java:760)
太难了,网上找的都是报的nextEntry()方法错误。而且我已经用了iterator,为什么还是删除出问题呢??