The error might be in pacman.Board. There's no way to check because I don't have the code, but ignoring add(new Board()), there are no errors that I can see or test for.
These probably won't fix the error if it's in pacman.Board, but here are some tips:
- Try to use more descriptive names and less similar names. The main class, the package that it is in, and the package that the board is in are named PacMan, pacman and packman. This could get confusing.
- The only thing that your constructor should be doing is setting things. It shouldn't be making new things (other than itself) or doing any work other than setting things. You should pass the new board into the PacMan constructor rather than build it *in* the constructor.
- Don't call overrideable methods from the constructor. (Methods that are neither private, static nor final.)
Taking the last two things into account, you may want to move all of your configuration code into a factory method. This would look as so:
public PacMan() {}
public static PacMan newInstance(final Board board)
{
final PacMan pacman = new PacMan();
pacman.setTitle("Pacman");
pacman.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pacman.setSize(380, 420);
pacman.setLocationRelativeTo(null);
pacman.add(board);
pacman.setVisible(true);
return pacman;
}
- Try not to couple things so tightly. Think of this: Does PacMan really have to be a JFrame? Could you instead make it a direct subclass of Object and build a JFrame to do that presentational work for PacMan? Could that JFrame built by PacMan be more abstract? Could the same code work with AWT Frames? At what score? What exactly is a pacman.Board?
Hope this helps! :)