Android SQLITE error android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

10-08 01:42:57.908: ERROR/AndroidRuntime(421): at android.database.AbstractCursor.checkPosition(
10-08 01:42:57.908: ERROR/AndroidRuntime(421): at android.database.AbstractWindowedCursor.checkPosition(
10-08 01:42:57.908: ERROR/AndroidRuntime(421): at android.database.AbstractWindowedCursor.getString(

The issue here is accessing the cursor when no records were returned. First check if there is data and then access the columns using the cursor. Here is sample code...
Cursor mCursor = mDb.query(SQLiteDatabase db, 
     String[] projectionIn, 
     String selection, 
     String[] selectionArgs, 
     String groupBy, 
     String having, 
     String sortOrder, 
     String limit);
if (mCursor != null) {
 if (mCursor.moveToFirst()) {
  String myData = mCursor.getString(mCursor.getColumnIndexOrThrow(KEY_DATA));
if (mCursor != null && !mCursor.isClosed()) {

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.