我很难为网格上的列数分配变量。我在实例化cols变量时收到错误。任何人都可以帮助我吗?
public void act()
{
Location place = getLocation();
Grid<Actor> gr = getGrid();
int cols = gr.getNumCols;
if (place.getCol() + 1 < cols)
moveTo(new Location(place.getRow(), place.getCol() + 1));
else
moveTo(new Location(place.getRow(), 0));
这是我收到的错误消息。
F:\Lab III Car and Teleporter\Car Project\Car.java:54: error: cannot find symbol
int cols = gr.getNumCols;
^
symbol: variable getNumCols
location: variable gr of type Grid<Actor>
1 error
Process completed.
答案 0 :(得分:1)
int cols = gr.getNumCols;
你错过了这里的副词。
这一行应该是(假设实际上有方法getNumCols()
):
int cols = gr.getNumCols();