I have a foreach loop iterating through each object in a vector. When I debug the code, it runs successfully for the first object in the vector. But then it will fail when it tries to run the loop for the second object. I am sure there is more than one element in the vector.
for(Object shape : vecForShapes)
{
currentNode = (Drawable) shape;
newNode = getResources().getDrawable(R.drawable.nodered);
newNode.setBounds(currentNode.getBounds());
vecForShapes.remove(currentNode);
vecForShapes.add(newNode);
}
So basically my question is, why is this loop failing? I really do not understand what is wrong here.
P.S. My final aim is to remove currentNode
from the vector, replace it with newNode
then redraw the whole vector in my onDraw
method.
Thanks