• 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

ConcurrentModificationException when painting component

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's also not modifying the list of cards - it's completely independent on input.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic