0

I'm designing a Tetris game in Gridworld. Below is the method that produces the error. It is a method of the Block class, which is a collection of Actors on which move and rotate methods can be called. myBlocks is an ArrayList of BlockSections.

public boolean canMoveDown() {
    Grid<Actor> g = myBlocks.get(0).getGrid();

    for (BlockSection b : myBlocks) {
        Location l = b.getLocation().getAdjacentLocation(180); // Error occurs here
        System.out.print(l);
        Actor bs = g.get(l);

        // Checks if a section of the block is at the bottom of grid,
        // and then whether, if there is a block below, if it is not
        // part of the current block floating down.
        if (b.getLocation().getRow() == 19 || (bs != null && myBlocks.indexOf(bs) == -1))
            return false;
        }
            return true;
        }
    }
}

I tried inserting a print statement to make sure Location is not null (which it shouldn't be, because all BlockSections being checked are in the grid) and it confirmed that the value was not null. However, the error continues to be generated. Help?

Thanks

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • I think b.getLocation() is null. Do null check before calling b.getLocation() as well as b.getLocation().getAdj.... – kosa May 22 '13 at 15:39
  • b could also be null. We don't know what's in myBlocks. – CPerkins May 22 '13 at 15:59
  • Two possibilities: `b` could be `null` (if `myBlocks` is a collection containing a `null` value); or `b.getLocation()` could be `null`. Split out the offending line by assigning `b.getLocation()` to an auxiliary variable, then you know which it is. (Alternatively, use a decent debugger.) Without knowing more about your code we can't say more. – Arend May 22 '13 at 21:40

0 Answers0