Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 网格世界为列数指定变量_Java - Fatal编程技术网

Java 网格世界为列数指定变量

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

我很难为网格上的列数指定一个变量。我在实例化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));
公共无效法案()
{
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()


为什么不显示错误消息?