Sqlite query returns mRowIdColumnIndex of -1
I need to check if there is already a value in one of my DB columns so I've written this code to do so:
public Cursor getTitle(long rowId) throws SQLException {
Cursor mCursor = db.query(DATABASE_TABLE, new String[]
{KEY_TOTAL_HOURS, KEY_TOTAL_MINUTES}, KEY_ROWID +"=" + rowId, null, null, null, null);{
mCursor.moveToFirst();
return mCursor;
}
}
But the cursor I'm getting back gives
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
开发者_如何学编程
What's wrong?
You should check the return value of moveToFirst to make sure there is a valid row returned: it will return false if there is not. It appears there is no row with the id you've specified.
精彩评论