Grokking the Object Oriented Design Interview
Ask Author
Back to course home

0% completed

Vote For New Content
E H
Null Pointer Exceptions

E H

Oct 8, 2024

  1. The Knight and King classes both have the following code to see if the end box has a Piece of the same colour as the King. If the Box is empty however, wouldn't getPiece return null, and in return throw an error when isWhite is called on it?
if (end.getPiece().isWhite() == this.isWhite()) { return false; }
  1. The boxes matrix is never initialized in the Board class, so "resetting" the board in the constructor will cause a null pointer exception.

0

0

Comments
Comments