gpt4 book ai didi

java - 如何修复线程 "main"java.util.ConcurrentModificationException 中的异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:50:51 33 4
gpt4 key购买 nike

<分区>

我有 2 HashMap<Integer,Point3D>对象名称是 positiveCoOrdinate and negativeCoOrdinates .

我正在检查 PositiveCoOrdinates条件如下,满足则对应点加入negativeCoOrdinates并从 positiveCoOrdinates 中删除.

  HashMap<Integer, Point3d> positiveCoOrdinates=duelList.get(1);
HashMap<Integer, Point3d> negativecoOrdinates=duelList.get(2);
//condition
Set<Integer> set=positiveCoOrdinates.keySet();
for (Integer pointIndex : set) {
Point3d coOrdinate=positiveCoOrdinates.get(pointIndex);
if (coOrdinate.x>xMaxValue || coOrdinate.y>yMaxValue || coOrdinate.z>zMaxValue) {
negativecoOrdinates.put(pointIndex, coOrdinate);
positiveCoOrdinates.remove(pointIndex);
}
}

在添加、删除时间时出现以下错误。

 Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at PlaneCoOrdinates.CoordinatesFiltering.Integration(CoordinatesFiltering.java:167)
at PlaneCoOrdinates.CoordinatesFiltering.main(CoordinatesFiltering.java:179)

为了测试,我提到了 System.out.println(coOrdinate.x);声明里面If条件。它工作正常。

如果我在 If 中添加 2 行(我上面提到的)条件,它抛出错误。

我该如何解决这个问题。

谢谢。

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