1

そのため、SimpleGraph (無向グラフ、JGraphT) のすべてのエッジを削除しようとしていますが、何らかの理由で ConcurrentModificationException が発生し続けます。

これが私がやろうとしていることです:

まず、次のようなクラス Point があります。

class Point
{
   private int x;
   private int y;

   public Point(int x, int y)
   {
      this.x = x;
      this.y = y;
   }

   //getters and setters 

   public boolean equals (Object rhs)
   {
      if (rhs == null || !(rhs instanceof Point))
         return false;
      else
      {
         Point rhsPoint = (Point) rhs;
         return rhsPoint.x == this.x && rhsPoint.y == this.y;
      }
   }

   public int hashCode()
   {
      int hash = 3;
      hash = 83 * hash + (int) (this.col ^ (this.col >>> 32));
      hash = 83 * hash + (int) (this.row ^ (this.row >>> 32));
      return hash;
   }
}

頂点が Point のインスタンスであり、2D 配列に格納されているグラフ g

Point[][] pointContainer = new Point[100][100];
SimpleGraph<Point, DefaultEdge.class> g = new SimpleGraph<Point, DefaultEdge.class>();

public void initGraph()
{
   for (int row = 0; row < 100; ++row)
     for (int col = 0; col < 100; ++col)
     {
        Point p = new Point(col, row);
        pointContainer[row][col] = p;
        g.addVertex(p);
     }

   //Then I added edges between any adjacent vertices
   //so except for those vertices near the edges of the grid, each vertex has 8 edges

}

public void removeEdges(int row, int col)
{
   Set edges = g.edgesOf(pointContainer[row][col]);
   g.removeAllEdges(edges);  
}

ここで私が間違ったことを誰か教えてもらえますか? ConCurrentModificationException が発生し続けるのはなぜですか?

4

1 に答える 1

1

ConCurrentModificationException許可されていない理由でアイテムを変更しようとしていることを意味します。つまり、コレクションを反復するときにコレクションを変更しようとすると発生します

エラーを検出するためにスタック トレースをチェックしてみてください。removeEdges()呼び出す場所で問題が発生する可能性があると思います

2番目に、あなたのPoint.equal()方法で、ポイントをセルにキャストする理由を説明していただけますか?

于 2013-01-17T15:26:04.840 に答える