gpt4 book ai didi

android 中的 java.util.ConcurrentModificationException(GLThread 23204)

转载 作者:行者123 更新时间:2023-11-29 20:06:24 25 4
gpt4 key购买 nike

尝试使用 Map 对象添加对象时,在此函数的第 4 行出现并发修改异常:

public void reloadResources() {
taskQueue.add(new GLResorceTask() { //ConcurrentLinkedQueue<GLResorceTask> taskQueue
public void perform(GLView gl) {
for(Entry<Resource, GLResourceLoader> entry : reloadMap.entrySet()) {
Resource res = entry.getKey();
if(res != null)
entry.getValue().load(res);
}
}
});
}

我做错了什么?

最佳答案

你可以试试

public void reloadResources() {
taskQueue.add(new GLResorceTask() { //ConcurrentLinkedQueue<GLResorceTask> taskQueue
public void perform(GLView gl) {
CopyOnWriteArrayList list = new CopyOnWriteArrayList(reloadMap);
for(Entry<Resource, GLResourceLoader> entry : list.entrySet()) {
Resource res = entry.getKey();
if(res != null)
entry.getValue().load(res);
}
}
});
}

关于android 中的 java.util.ConcurrentModificationException(GLThread 23204),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35602089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com