给出以下代码:
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 i = robotList.iterator(); i.hasNext();)
{
// Robot currentRobot = (Robot) i.next();
robotX = ((Robot)(i)).getXlocation();
robotY = ((Robot)(i)).getYlocation();
// more code , irrelevant
}我有以下对象:Robot,GeometricElement和Dot。
我想在一个Robot链接列表上进行迭代,其定义如下:
public class Ground {
// more fields
private LinkedList robotList; // used for storing the robots
public Ground(int row,int col) // ctor
{
// some code
this.robotList = new LinkedList();
}
}但行:robotX = ((Robot)(i)).getXlocation();
和robotY = ((Robot)(i)).getYlocation();
抛出dispatchUncaughtException的异常。
请注意,我不想从链接列表中删除元素,
我需要的是从迭代器中获取当前元素的字段。
那么,怎么了?
问候
罗恩