2011-12-03 4 views
0

グリッドの列数に変数を割り当てるのが難しいです。私は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。

ここに小文字がありません。

このラインshouldeが(メソッドgetNumCols()が実際に存在すると仮定して)されなければならない:

INT COLS = gr.getNumCols()。

+0

あなたは正しいです、ありがとうございます。 –