Java, ArrayList and Exception in thread “AWT-EventQueue-0” java.util.ConcurrentModificationException
来源:互联网 发布:万网中文域名注册 编辑:程序博客网 时间:2024/05/17 18:43
Java, ArrayList and Exception in thread “AWT-EventQueue-0” java.util.ConcurrentModificationException
iterating through an ArrayList. If I use the old fashion way
for (int i = 0; i < list.size(); i++){ list.get(i).update();;}
it runs ok. But with this:
for (Baseitem item : list){ item.update();}
it fails at the first line, inside ArrayList class: Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException yes, outside I do remove items - but certainly not while iterating. How to solve this? I dont use any threads.
You should avoid modifying elements in a list while iterating that list.
With the for (int i...)
loop, you are not iterating the list, so you can modify the elements inside.
In the for (Baseitem item : list)
loop, you are iterating the list, so the modification of the elements of the list will raise the ConcurrentModificationException
exception.
You have to use the first form of the loop if you want to modify the elements inside it.
以上就是发生这种异常的表面现象。
0 0
- Java, ArrayList and Exception in thread “AWT-EventQueue-0” java.util.ConcurrentModificationException
- Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
- Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
- 异常Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- 异常Exception in thread "AWT-EventQueue-XX" java.lang.StackOverflowError
- Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException:
- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationException
- iOS ARC机制 weak strong
- 淘宝海量数据产品技术架构
- hdu-2076-夹角有多大(题目已修改,注意读题)
- LeetCode: Best Time to Buy and Sell Stock III
- VBS获取天气预报[BY Broly]
- Java, ArrayList and Exception in thread “AWT-EventQueue-0” java.util.ConcurrentModificationException
- R: 控制台的清理与输出内容的保存 (Clear Console & Save Console Output)
- 详细介绍windows下使用python pylot进行网站压力测试
- 敏捷文档编制路线图
- Textviewb设置背景色失效
- Windows API函数大全
- 计算出表格里多行商品的总价
- 微信第三方登录
- 程序员不得不知道的英语词汇