Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look closely :) This</p> <pre><code>if (!db.isOpen() || db != null) { db.close(); db = null; } </code></pre> <p>will try to close the db only if it is <strong>not open</strong>. Also, I think there's something wrong with the</p> <pre><code>|| x != null </code></pre> <p>part of both clauses.</p> <p>In Java, the "double" logical operators are <em>conditional</em>. For || that means if the first argument is <strong>true</strong> then the second argument will not be evaluated at all, since logical OR will already be true no matter what. If it's not - then your link is checked for null. So, what you're doing is, you check whether cursor is closed. And if it <strong>is</strong> closed, you check the link for null - which obviously will be true given you succeeded calling any method on it, so no use of the second check.</p> <p>I think the right clauses will be</p> <pre><code>if ( poisCursor != null &amp;&amp; !poisCursor.isClosed()) // prevent NPE when calling .isClosed() in case poisCursor is null </code></pre> <p>and</p> <pre><code>if (db != null &amp;&amp; db.isOpen()) // same thing + note the absence of negation </code></pre> <p>(You can read more on conditional operators in detail here: <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html</a>)</p> <p><strong>Edit:</strong> @firebolt7 is right, you're losing reference to the object you get when calling open() in if clause.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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