Here is what happens
The NullPointer Exception happens in Source File GUIController.java as indicated by the stacktrace.
Grid<T> gr = parentFrame.getWorld().getGrid();
Location loc = display.locationForPoint(evt.getPoint());
if (loc != null && gr.isValid(loc) && !isRunning())
gr
, which is retreived from getWorld().getGrid()
can be null and the if statement does not check gr before calling gr.isValid()
.
Tracing the Source:
The Grid gets set by the setGrid()
method in WorldFrame.java, which does not check its imput, that is, if you call the method with null
, it will set the new grid to null.
The setGrid()
method is beeing called from MenuMaker.java (line 343)
Grid<T> newGrid = (Grid<T>) invokeConstructor();
parent.setGrid(newGrid);
and the invokeConstructor()
method returns null on exceptions.
This is, where your null comes from
Fix
Make sure that setGrid in WorldFrame.java does not accept null values as parameter.
public void setGrid(Grid<T> newGrid) {
if (newGrid == null) {
return;
}
// rest of method goes here
An probably better, yet more complex, solution would be, to ensure that invokeConstructor()
in MenuMaker.java
does not return null. Notifying the GUI and handling the Exception (instead of returning null) would be a more elegant solution.
Hope this helps.