Consider this Method in a DatabaseHelper class:
public Cursor getRules()
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cur=db.rawQuery("SELECT * from Rules",new String [] {});
Log.d("Cursor Size", "" + cur.getCount());
db.close();
return cur;
}
It returns a Cursor and on the activity, I consume it like
Cursor ruleCursor=DatabaseHelper.getInstance(this).getRules();
if(ruleCursor!=null)
{
RuleManager.getInstance(this,null).loadRules(ruleCursor);
ruleCursor.close();
}
(I am not moving the entire cursor handling inside the DatabaseHelper class and return just a list of Objects instead of cursor), the problem is that if I don’t Log.d in getRules(), entire program fails. i get an “Invalid Statement in fillWindow()” error, and SQLite doesn’t return any row on a “Select” statement.
Just adding a Log.d for cursor.getCount() solves everything. Also, to mention, this thing was working fine till yesterday and is behaving like this from the last evening.
Am I missing something? Is this behavior expected?
Try using this
//Stop worrying about the DatabaseHelper here.
//and where ever you use the Cursor(or “Consume” your cursor) just.
Hope it helps you!!