• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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: 23956
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: 23956
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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic