I am writing a code that determines if an item can be eaten. If it is edible, I return a give message.
Here is my code:
public void eat(String item){
//update the game's message with one of the following options:
//1:"you are not holding an item"
//2:"item is not edible"
//3:"Yum, that was a tasty item!"
if(items == null){
message = "You are not holidng anything.";
}
else{
for(Item i: items){
if(i.isEdible()){
message = "Yum, that was tasty!";
items.remove(i);
}
else{
message = "That is not edible.";
}
}
}
}
When I run the above, I get:
java.util.ConcurrentModificationException:
null(in java.util.ArrayList$itr)
What does this error mean? What can I do to fix this?