dimanche 8 novembre 2015

Sqlite - getting Index 0 requested, with a size of 0

i'm trying to get one contact from my db, i keep getting Index 0 requested, with a size of 0 error.

this is my code:

// Getting single contact
Contact getContact(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, new String[]
                    { COLUMN_ID, COLUMN_FULLNAME, COLUMN_PHONE, COLUMN_EMAIL, COLUMN_ADDRESS, COLUMN_SITE, COLUMN_BIRTHDAY },
                    COLUMN_ID + "=?",
                    new String[] { String.valueOf(id) }, null, null, null, null);


    if (cursor != null)
        cursor.moveToFirst();

        Contact contact = new Contact(
            Integer.parseInt(cursor.getString(0)),
            cursor.getString(1),
            cursor.getString(2),
            cursor.getString(3),
            cursor.getString(4),
            cursor.getString(5),
            cursor.getString(6));
    db.close();
    cursor.close();
    return contact;
}

this is the error i'm getting:

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

plz help me understand what to do...

Aucun commentaire:

Enregistrer un commentaire