So this question is a little bit different from the others i've found on here about concurrent exception when modifying the list- because this happens when im modifying an internal list of an object within the list. This is the only method accessing the internal list
Here's where i call the method
public void interactWithItem(int targetIDX, int targetIDY){
for(Iterator<Item> it = listOfAllItems.iterator(); it.hasNext();){
Item tempItem = it.next();
//Maybe i should refine more, in world, so forth
if(tempItem.tilePosX == targetIDX && tempItem.tilePosY == targetIDY){
if(tempItem.name.equals("chest")){
System.out.println("Interacting with Chest!");
if(!tempItem.containedItems.isEmpty()){
for(Iterator<Item> tempIt = tempItem.containedItems.iterator(); tempIt.hasNext();){
Item tItem = tempIt.next();
System.out.println("Chest contains "+tItem.name+" "+tItem.amount);
Character.c.addItem("player", tItem.name, tItem.amount);
removeContainedItem("chest", tItem.name);
}
}else{
System.out.println("Chest is empty");
}
}
}
}
}
Here's the method that causes the issue, if i comment out the i.remove(); the issue seizes to happen- so its only upon removal, yet no other method or class is accessing the internal list ?
public void removeContainedItem(String containerName, String itemName){
System.out.println("Removing "+itemName+" in "+containerName);
for(Iterator<Item> it = listOfAllItems.iterator(); it.hasNext();){
Item tItem = it.next();
if(tItem.name.equals(containerName)){
for(Iterator<Item> i = tItem.containedItems.iterator(); i.hasNext();){
Item tempItem = i.next();
System.out.println(tempItem.name);
if(tempItem.name.equals(itemName)){
i.remove();
}
}
}
}
}
Thanks for all the help! Hope someone can clarify and give me instructions as to how i might go about fixing this thing? Im a bit at a loss.