• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.util.ConcurrentModificationException - ArrayList override  RSS feed

 
Frederik Pedersen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a program which send the content of an ArrayList from client to server. The ArrayList is the content of points drawn on a canvas, which means it constantly gets updated as the user draws. However when I draw for a longer period of time (few seconds), I get following error:


I believe the error occurs because of the ArrayList trying to override an ArrayList that is already sending (or at least some sort of override). Reasoned the error only happens if I draw while my main thread is sending a package.

What I've tried:

- Creating a mouseReleased adapter, where the OutputStream only is active when the user isn't drawing

- Binding a button to activate the OutputStream

With both attemps I've failed to achieve success, so I would like some help to work out how this would be done most effeciently, to remove this error.

My client:

 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.
That stack trace shows it writing to the output stream, which involves iterating over the List. At the same time something (as you suggest, one of the mouse events) is adding to the List, which is not allowed.

Why are you constantly sending the List, though?
Surely you just want to send a new Point each time it's added?
 
Frederik Pedersen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Yep.
That stack trace shows it writing to the output stream, which involves iterating over the List. At the same time something (as you suggest, one of the mouse events) is adding to the List, which is not allowed.

Why are you constantly sending the List, though?
Surely you just want to send a new Point each time it's added?


Sending a Point each time it's added seems more obvious now you mension it. I'm just past beginner at Java, and a total beginner at networking. How would you suggest going around this?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!