CopyOnWriteArrayList
in
Programming Questions
•
1 year ago
I've run into a major issue with my program where I occasionally get a ConcurrentModificationException.
One possible reason is that when the user clicks the erase button (which removes all point objects from the ArrayList), the program could be concurrently iterating through that same ArrayList in order to draw a point to the screen.
One fix that I have seen is to use CopyOnWriteArrayList. However, when I try creating a CopyOnWriteArrayList, I get the error that it cannot find a type or class named as this.
I even imported java.util.
Does Processing not support the use of CopyOnWriteArrayList?
Is there a way to get around this?
Also, for added detail...
Here are the possible operations that can be done on my ArrayList in my program.
Add a newly calculated point object to ArrayList
Draw point objects in ArrayList to the screen using an Iterator
Remove points from ArrayList if user does not want previous points to still appear on screen using an Iterator
User presses erase button which removes all point objects from ArrayList. This is done so using an iterator
The only time I get the ConcurrentModificationException is when I click the erase button.
And the error is highlighted in the block of code that draws a point to the screen.
Code Segment:
for(Iterator<Point> it = PointArray.iterator(); it.hasNext();)
{
Point pa = it.next(); //This is the line that is highlighted
drawPoint(pa);
}
Any suggestions in fixing this would be great.
1