我正在尝试创建一个代码,如果演员是打开的,它将演员移动到一个随机的位置。但是,我很难解决此行导致的错误。

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上可用

10-06 06:03