我正在尝试创建一个代码,如果演员是打开的,它将演员移动到一个随机的位置。但是,我很难解决此行导致的错误。
if (null == get(loc))
基本上我以为这条线会检查位置是否打开。但是我收到此错误,任何人都可以帮忙吗?
F:\Lab III Car and Teleporter\Teleporter Project\TeleporterActor.java:42: error: cannot find symbol
if (null == get(loc))
^
symbol: method get(Location)
location: class TeleporterActor
1 error
Process completed.
public void act()
{
Location place = getLocation();
Grid<Actor> gr = getGrid();
int cols = gr.getNumRows();
int rows = gr.getNumCols();
do
{
Location loc = new Location((int)(Math.random() * rows - 1), (int)(Math.random() * cols - 1));
if (null == get(loc))
moveTo(loc);
}
while (place == getLocation());
}
最佳答案
该错误表示get
类中没有TeleporterActor
方法,因此编译器不知道使用get
的含义。
将这样的方法添加到您的TeleporterActor
类中,或者在另一个对象上调用它,例如
gr.get( loc );
我假设
get
方法在您的Grid
上可用