Pergunta

I am attempting to create a code that will move an actor to a random location if it is open. However, I am having difficulties with an error that results from this line.

if (null == get(loc))

Basically I thought this line would check if the location was open. However I'm getting this error can anyone help?

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());  
    }
Foi útil?

Solução

The error means you do not have a get method in your TeleporterActor class, hence the compiler does not know what you mean by using get.

Either add such a method to your TeleporterActor class, or call it on another object, for example

gr.get( loc );

where I assumed the get method is available on your Grid

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top