• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

ConcurrentModificationException when painting component  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm making a small card game in Java with Swing, and I've run into a problem.
I have the following code when you drag with your mouse:



What it's supposed to do, is when you first click on a stack of cards, it removes the stack of cards from the field, and then puts it on the drag panel.
This is the DragPanel class:


Which is calling a method from CardImager, which doesn't modify the card in any way.
Do any of you have any insight?
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kees Jacobsen wrote:
Which is calling a method from CardImager, which doesn't modify the card in any way.
Do any of you have any insight?




It is not "card" -- it is "cards". You are not allowed to modify the List of cards while you are iterating through it. If you want to modify the list, you are only allowed to do it via the iterator, which you haven't exposed in your code.

Henry
 
Kees Jacobsen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also not modifying the list of cards - it's completely independent on input.
 
Henry Wong
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kees Jacobsen wrote:It's also not modifying the list of cards - it's completely independent on input.



Well, something is modifying that list. That error occurs when the list is modified while iteration is taking place -- and that modification can come from your code, or some other code not related to your method call, or thread of execution.

Henry
 
Kees Jacobsen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the problem is, I don't know what and why.
Without any body, the for loop where the stackTrace points to still causes problems.
Doing anything else, like printing the size of the 'cards' array, also causes a ConcurrentModificationException.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!