title: android-how to close cursor in a class like this
body: <p>I have this function inside my dbhelper class :</p>
  
  <pre><code>public Cursor getRow(long rowId) {
      String where = KEY_ROWID + "=" + rowId;
      Cursor c = db.query(DATABASE_TABLE, ALL_KEYS, where, null, null, null,null, null);
      if (c != null) {
          c.moveToFirst();
      }
  
      return c;
  }
  </code></pre>
  
  <p>when I come to the activity where this class calls, I get this error (Please notice when I enter this activity I get this error not when leaving the activity ):</p>
  
  <pre><code>Finalizing a Cursor that has not been deactivated or closed. database......
  Application did not close the cursor or database object that was opened here
  </code></pre>
  
  <p>it's a very long error .</p>
  
  <p>someone told me to use c.close(); above return c, something like this:</p>
  
  <pre><code>public Cursor getRow(long rowId) {
          String where = KEY_ROWID + "=" + rowId;
          Cursor c = db.query(DATABASE_TABLE, ALL_KEYS, where, null, null, null,null, null);
          if (c != null) {
              c.moveToFirst();
          }
          c.close();
          return c;
      }  
  </code></pre>
  
  <p>I tried it but now I get this error :</p>
  
  <pre><code>Access closed cursor
  </code></pre>
  
  <p>What should I do ? How should I close the cursor in this class? </p>