Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload