我知道什麼是ConcurrentModificationException。我之前有過它們,我之前解決過它們,我可以用迭代器逃脫。 但是,在這種情況下,我不明白爲什麼它被拋出。ConcurrentModificationException的可能原因
public boolean pointOnEdgeBlob(int x, int y, float edgeHitEpsilon) {
init();
for (int i = 0; i < nOfBlobs; i++) {
Blob b = blobs.get(i);
// >>>>>>>>>>>>>>>>>>>>> here it calls the method where it goes wrong
if (b.edgeHit(x, y, edgeHitEpsilon)) return true;
}
return false;
}
這裏是edgeHit方法,它在團塊:
public boolean edgeHit(float x, float y, float edgeHitEpsilon) {
// quick test if it's worth it
if (x < getMinX()-edgeHitEpsilon || x > getMaxX()+edgeHitEpsilon || y < getMinY()-edgeHitEpsilon || y > getMaxY()+edgeHitEpsilon) {
return false;
}
// the last one should be connected to the first
// >>>>>>>>>>>>>>> if i comment the part in the for loop then this get's the problem.
PVector pre = cornerVectors.get(cornerVectors.size() -1);
PVector cur;
for (int i = 0; i < cornerVectors.size(); i++) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> on this line it throws
cur = cornerVectors.get(i);
if(Blob.onLine(pre, cur, x, y, edgeHitEpsilon)) {
return true;
}
pre = cur;
}
return false;
}
更新:
cornerVectors是一個列表視圖:
List<PVector> cornerVectors;
它得到的設置有:
list.subList(fromIndex, toIndex);
沒有其他威脅在運行。
這裏是堆棧跟蹤:
在 java.util.SubList.checkForComodification(AbstractList.java:752)異常在線程 「動畫線程」 java.util.ConcurrentModificationException在 java.util中.SubList.size(AbstractList.java:625)at nl.doekewartena.contour.scanner.Blob.edgeHit(Blob.java:229)at nl.doekewartena.contour.scanner.BlobData.pointOnEdgeBlob(BlobData.java:333 ) at nl.doekewartena.contour.scanner.ContourFinder.scan(ContourFinder.java:555) at nl.doekewartena.contour.scanner.ContourFinder.scan(ContourFinder.java:469) at exclude.T04_ContourFinder.draw(T04_ContourFinder.java:38)at processing.core.PApplet.handleDraw(PApplet.java:2386 )在在 java.lang.Thread.run(Thread.java:695 processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) 在processing.core.PApplet.run(PApplet.java:2256))
那麼,什麼是'cornerVectors'? – 2014-12-03 02:30:45
而其他線程沒有活動? – 2014-12-03 02:32:48
我相當肯定有些事情你沒有告訴我們。 – 2014-12-03 02:50:12