小编Har*_*ian的帖子

我找不到java.util.ConcurrentModificationException的原因

我有代码在我的Main方法中进入for循环.

for (List<Point2D> points : output) {
    currentPath = pathDistance(points);
    if (shortest == 0){
        shortest = currentPath;
    } else if (currentPath < shortest) {
        best = points;
        shortest = currentPath;
    }
}
Run Code Online (Sandbox Code Playgroud)

在哪里pathDistance定义为

public static Double pathDistance(List<Point2D> path){
    double distance = 0;
    int count = path.size()-1;

    for (int i = 0; i < count; i++) {
        distance = distance + path.get(i).distance(path.get(i+1));
    }

    distance = distance + path.get(0).distance(path.get(count));
    return distance;
}
Run Code Online (Sandbox Code Playgroud)

但我一直在收到错误

Exception in thread "main" java.util.ConcurrentModificationException
   at java.util.SubList.checkForComodification(Unknown …
Run Code Online (Sandbox Code Playgroud)

java concurrentmodification

5
推荐指数
1
解决办法
288
查看次数

标签 统计

concurrentmodification ×1

java ×1