dimanche 1 novembre 2015

Reading Sqlite Cursor carsh on Android 4.2 API 17

I have a table with 145 rows. when i try to get all of it's data it getting crashed on android 4.2, BUT it works fine on android 4.4 emulator.

public ArrayList<QuestionInfoHolder> getAllArticle()
    {
        ArrayList<QuestionInfoHolder> result = new ArrayList<QuestionInfoHolder>();
        SQLiteDatabase db = getReadableDatabase();
        String query = "SELECT * FROM " + ARTICLE_TABLE_NAME + " ORDER BY "+ QUESTION_DATE +";";
        Cursor cursor = db.rawQuery(query, null);
        if(cursor != null)
        {
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
            {
                result.add(new QuestionInfoHolder(cursor.getInt(0),
                        cursor.getInt(1),
                        cursor.getString(2),
                        cursor.getString(3),
                        cursor.getString(4)));
            }
        }

        return result;
    }

the logcat:

Failed to read row 9, column 0 from a CursorWindow which has 9 rows, 5 columns.
FATAL EXCEPTION: main
java.lang.IllegalStateException: Couldn't read row 9, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

this says the cursor has only 9 rows, but if i log cursor.getCount(); it will show 145.

i can not figure out what is the problem. so any help or suggestion will be appreciated.

Aucun commentaire:

Enregistrer un commentaire