Concurrent Modification Exception?

eds01

Diabloii.Net Member
Concurrent Modification Exception?

So I'm writing a program for my cse115 class (quite literaly, it has to do something with graphics, we get to decide what we're doing), and i'm running into an error i have no idea how I'm getting. The error is, as the title suggests, a Concurrent Modification Exception, and I'm programming in java. I'm pretty sure its from this one 2-d array that i have filled up with a type of graphic, but i'm not sure what's actualy wrong with it. What I'm doing with the array is just filling it up in a nested for loop, and then displaying the values on the screen. I'll post the code later (not currently at the lab where i have the code stored).
 

Gertlex

Banned
So I'm writing a program for my cse115 class (quite literaly, it has to do something with graphics, we get to decide what we're doing), and i'm running into an error i have no idea how I'm getting. The error is, as the title suggests, a Concurrent Modification Exception, and I'm programming in java. I'm pretty sure its from this one 2-d array that i have filled up with a type of graphic, but i'm not sure what's actualy wrong with it. What I'm doing with the array is just filling it up in a nested for loop, and then displaying the values on the screen. I'll post the code later (not currently at the lab where i have the code stored).
I never learned that much java, but that error sounds like maybe you're using threads? Concurrently = at the same time, so two threads trying to modify the same variable at the same time?



 

myleftfoot

Diabloii.Net Member
So I'm writing a program for my cse115 class (quite literaly, it has to do something with graphics, we get to decide what we're doing), and i'm running into an error i have no idea how I'm getting. The error is, as the title suggests, a Concurrent Modification Exception, and I'm programming in java. I'm pretty sure its from this one 2-d array that i have filled up with a type of graphic, but i'm not sure what's actualy wrong with it. What I'm doing with the array is just filling it up in a nested for loop, and then displaying the values on the screen. I'll post the code later (not currently at the lab where i have the code stored).
Are you removing items from the list?



 

eds01

Diabloii.Net Member
As far as i know, the programs single threaded, and i'm not actualy removing any refrences - i made the graphic in the array a type of compound graphic, so i can just change what kind of circle is on the intersection (I'm coding a GUI for go, so theres only 3 states a intersection can have - it can have a black stone on it, a white stone or it can just have nothing). Also, i put the code for changing whats on the intersection to be inside the compound graphic, so other classes just call a playBlack() or playWhite() method.
 

Eritar

Diabloii.Net Member
Assuming you're making some use of the Swing classes, I believe that Swing components get a separate thread of execution automatically. I think. :wink3: I'm no Java expert either, and knowing this doesn't really help you, anyway.
 

eds01

Diabloii.Net Member
I think that the extended graphic that I'm useing comes from the libraries provided by the teachers (I'm currently at home and the codes at school, so...), but I wouldent be half suprised if the code in that extends java.awt and javax.swing.

What can i do to stop the concurrent modification if it does in fact, come from the use of swing?
 

Quietus

Diabloii.Net Member
I didn't pay that much attention in my Java class, unfortunately, but I'm pretty sure that I remember 2d graphics in Java working much the same as they did when I worked in C++... in which case, there's a good chance that what's happening is that you aren't locking the surface that you're working on. I'm afraid I can't be of much help in just giving the commands to do so, as I said, I didn't pay much attention to Java... but I distinctly remember having to lock a surface, draw to it, unlock it, then show it.

As was pointed out before, Concurrent means "at the same time" - which means Concurrent Modification would mean two things trying to change something at the same time. That's going to end up pouring a pile of garbage out at you, ending up in an error like this. Try troubleshooting, and see if you can figure out which variables are being altered when the program crashes.
 
Top