• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic