Could not read row 0, column 0 from CursorWindow which has 0 rows, 1 column
I have an Android app that is trying to download a blob from a SQLite database as a byte array:
public byte[] getBytesForId(long id){
byte[] result = null;
String sql = "SELECT _blob FROM test_table WHERE _id=?";
String[] selection = new String[] { String.valueOf(id) };
Cursor mCursor = super.DB().rawQuery(sql, selection);
if ( mCursor != null && mCursor.moveToFirst() ) {
if (mCursor.getCount() > 0)
result = mCursor.getBlob(0);
if (mCursor != null && !mCursor.isClosed())
mCursor.close();
}
return result;
}
but I am getting the following exception:
Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 1 columns.
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetBlob(Native Method)
at android.database.CursorWindow.getBlob(CursorWindow.java:404)
at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:45)
at com.test.testapp.model.DbClass.getBytesForId(DbClass.java:218)
at com.test.testapp.TestService.StepThroughBlocks(TestService.java:434)
at com.test.testapp.TestService.checkBlocks(TestService.java:378)
at com.test.testapp.TestService.access$4(TestService.java:357)
at com.test.testapp.TestService$2.run(TestService.java:315)
at java.lang.Thread.run(Thread.java:841)
Of course, if I check that the cursor has some data first ...
if ( mCursor != null && mCursor.moveToFirst() )
if (mCursor.getCount() > 0)
result = mCursor.getBlob(0);
... I shouldn't get this exception? I added the line mCursor.getCount which might help, but I still get the exception. How is this possible?
+3
source to share
No one has answered this question yet
Check out similar questions: