Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Lets look at that "line":</p> <pre><code> if (by &gt;= bricks[0].y &amp;&amp; by &lt;= bricks[0].y + bricks[0].img.getHeight(null) &amp;&amp; bx &gt;= bricks[0].x &amp;&amp; bx &lt;= bricks[0].x + bricks[0].img.getWidth(null)) { </code></pre> <p>Assuming that <code>bx</code>, <code>by</code>, and the <code>x</code> and <code>y</code> fields are all primitive types (e.g. <code>int</code>), then here's a list of things that <em>could</em> result in an NPE:</p> <ul> <li>the <code>bricks</code> variable is <code>null</code></li> <li>the zeroth element of <code>bricks</code> is <code>null</code></li> <li>the value of <code>bricks[0].img</code> is <code>null</code></li> </ul> <p>If <code>bx</code>, <code>by</code>, <code>x</code> and/or <code>y</code> is a wrapper type, then one of those could be <code>null</code>. That would lead to an NPE when unboxing the value.</p> <p>It is not caused by passing <code>null</code> to the <code>getHeight</code> or <code>getWidth</code> methods, because 1) I believe that is valid and 2) if it wasn't then the NPE would be thrown in a different place to what you stacktrace shows.</p> <p>(I can't tell if passing <code>null</code> in those calls is <em>correct</em> ... but either way, it is not the cause of this NPE based on the evidence you have provided.)</p> <hr> <p>If you want to figure what is <em>actually</em> causing the problem, debug the code or add some traceprints to <em>test</em> which of the things that could be <code>null</code> is actually <code>null</code>.</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