С учетом следующего кода:
public void insertIntoQueue(float length,int xElement,int yElement,int whichElement)
{
Dot dot = new Dot(xElement,yElement);
GeometricElement element = null;
// some code
int robotX,robotY;
boolean flag = false;
for (Iterator<Robot> i = robotList.iterator(); i.hasNext();)
{
// Robot currentRobot = (Robot) i.next();
robotX = ((Robot)(i)).getXlocation();
robotY = ((Robot)(i)).getYlocation();
// more code , irrelevant
}
У меня есть следующие объекты: Robot, GeometricElement и Dot.
Я хочу перебрать связанный список роботов, который определен как:
public class Ground {
// more fields
private LinkedList <Robot> robotList; // used for storing the robots
public Ground(int row,int col) // ctor
{
// some code
this.robotList = new LinkedList<Robot>();
}
}
но строка: robotX = ((Robot)(i)).getXlocation();
и роботY = ((Robot)(i)).getYlocation();
выдает исключение dispatchUncaughtException
.
Обратите внимание, что я не хочу удалять элементы из связанного списка,
мне нужно получить поля из текущего элемента с помощью итератора.
Так что не так?
С уважением
Рон