Checking if the table has rows results in Null Pointer Exception in SQLiite Android : <p>I want to check if the table has rows and if it contains, then I want to delete it. Below is my code for checking if table has rows in it.</p>

<pre><code>     boolean empty = true;
    Cursor cursor = db.rawQuery("SELECT count(*) FROM TABLE_NAME",null);
    cursor.moveToFirst();
    if (cursor.getInt(0) &gt; 0)
    {
        empty = false;
    }
    else
    {
        empty= true;
    }
    return  empty; 
</code></pre>

<p>I even tried checking with below code,</p>

<pre><code>    boolean empty = true;
    Cursor cur = db.rawQuery("SELECT COUNT(*) FROM TABLE_NAME", null);
    if (cur != null &amp;&amp; cur.moveToFirst()) {
        empty = (cur.getInt (0) == 0);
    }
    cur.close();

    return empty;    
</code></pre>

<p>Both of the above code, throws NullPointerException in line</p>

<p>("SELECT COUNT(*) FROM TABLE_NAME", null);</p>

<p>Any help would be great !! Thanks </p>
