Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  ConcurrentModificationException  (Read 594 times)
0 Members and 2 Guests are viewing this topic.
Offline Soljaragz

Jr. Member
**

Posts: 55



« on: 2006-02-05 23:19:09 »

I keep getting this error with this code

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   public boolean attackElement(int arrayIndex, int listIndex, int damage)
   {
     
      ((Enemy)enemyList[ arrayIndex ].get(listIndex) ).attack(damage);
      if( ( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getHp()<=0)
      {
         elementsArray[( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getIdRow()][( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getIdCol()] = null;
         enemyList[arrayIndex].remove(listIndex); // this code causes error
        return true;
      }
      else
         return false;
   }      


what does that mean? I read the definition but i didn't understand it
1  
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #1 on: 2006-02-06 03:59:17 »

Why starting a new thread for the same problem?

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Soljaragz

Jr. Member
**

Posts: 55



« Reply #2 on: 2006-02-06 09:17:54 »

my bad lol, but why would this error happen?
Games published by our own members! Go get 'em!
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #3 on: 2006-02-06 09:27:35 »

Read the JavaDocs for that method

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Maverick

JGO n00b
*

Posts: 12



« Reply #4 on: 2006-02-06 11:08:17 »

this might help you:
CopyOnWriteArrayList

its in java.util.List
Offline Soljaragz

Jr. Member
**

Posts: 55



« Reply #5 on: 2006-02-06 15:13:30 »

Read the JavaDocs for that method



if you read my first post , i said i already read the java docs but i didnt understand the circumstances for the error to happen.

But so i am guessing the error happens BECAUSE im trying to change the arrayList while im iterating through it? am i correct?

if that is the case, than whats some options that i could use???
wouldnt a CopyOnWriteArrayList be too slow
Offline Soljaragz

Jr. Member
**

Posts: 55



« Reply #6 on: 2006-02-06 19:44:50 »

Ah ok! I understand now why I get this error (after making a few test appliacations),

My code was suppose to put the enemy in a different ArrayList each time he moves, but sometimes he would be in the same arrayList, and therefore adding to the current ArrayList while iterating through it at the same time will cause the error!!
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.07 seconds with 19 queries.