Java 网格世界为列数指定变量
我很难为网格上的列数指定一个变量。我在实例化cols变量时收到一个错误。有人能帮我吗Java 网格世界为列数指定变量,java,Java,我很难为网格上的列数指定一个变量。我在实例化cols变量时收到一个错误。有人能帮我吗 public void act() { Location place = getLocation(); Grid<Actor> gr = getGrid(); int cols = gr.getNumCols; if (place.getCol() + 1 < cols) moveTo(n
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));
公共无效法案()
{
Location-place=getLocation();
Grid gr=getGrid();
int cols=gr.getNumCols;
if(place.getCol()+1
这是我收到的错误消息
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.
F:\Lab III Car and Teleporter\Car Project\Car.java:54:错误:找不到符号
int cols=gr.getNumCols;
^
符号:变量getNumCols
位置:Grid类型的变量gr
1错误
进程已完成。
int cols=gr.getNumCols
你错过了这里的偏执。这一行应该是(假设实际上有一个方法
getNumCols()
):
int cols=gr.getNumCols()
为什么不显示错误消息?