vendredi 11 mars 2016

Android-sqlite Couldn't read row 0, col -1 from Cursor Window

I am trying to get a value from the table.

 cursor=db.rawQuery("select value from '" + tableName + "' where key= '" + name + "' ",null);

if (cursor.getCount()>0){
        if (cursor.moveToFirst()){
                String value= cursor.getString(cursor.getColumnIndex("value"));
                return value;
        }
        cursor.close();

    }

I get the exception:

Couldn't read row 0, col -1 from Cursor Window.Make sure cursor is initialised correctly before accessing data from it.

When I use:

        cursor.getString(0);

I am able to get the value I need.

If I use,

       cursor.getString(cursor.getColumnIndex("value"));

I get the exception.

HEre is the snapshot of my table: enter image description here

Aucun commentaire:

Enregistrer un commentaire