Search code examples
androidsqlitecursorillegalstateexception

Trying to requery an already closed cursor


I'm doing simply queries like:

Cursor c = databaseHelper.getReadableDatabase().rawQuery("select " + MyTable.TABLE_FIELD.getColumnName() + " from " + MyTable.TABLE_NAME, null);

after that I extract the data needed and populate some views.

c.close();

Everything works as expected. I have a share intent to send an e-mail with some of the information shown. The java.lang.IllegalStateException is thrown after the e-mail app sends the e-mail or closes and my activity is brought back to "life". This exception is only thrown in this situation, if I send it to background and then call it again this exception isn't thrown. I even have an intent to open youtube and play a video and this exception isn't thrown...

I really don't know why this is happening.

Thanks for your time.

ps: I've tried //c.close(); but it didn't work either.


Solution

  • I found what was causing this problem. Some of the e-mail's information was fed by another cursor from an "utils" class. This cursor was closed after providing the information to the e-mail and this was causing the problem. Instead of c.close(); I changed to c = null; and now it's working.

    Probably not the best solution, but for now it's working. Thanks.