Domanda

Sto tentando di creare un codice che sposterà un attore in una posizione casuale se è aperto. Tuttavia, ho difficoltà con un errore che risulta da questa riga.

if (null == get(loc))

Fondamentalmente pensavo che questa linea avrebbe verificato se la posizione fosse aperta. Tuttavia sto ricevendo questo errore, qualcuno può aiutare?

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());  
    }
È stato utile?

Soluzione

L'errore significa che non hai un file get metodo nel tuo TeleporterActor classe, quindi il compilatore non sa cosa intendi usando get.

O aggiungi un tale metodo al tuo TeleporterActor classe o chiamalo su un altro oggetto, ad esempio

gr.get( loc );

dove ho assunto il get Il metodo è disponibile sul tuo Grid

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top