java.lang.IllegalStateException: error al obtener el espacio de campo de la fila 0 col -1

I have table in sqlite that contain only one record and I want to access that in cursor but facing problem I got this exception java.lang.IllegalStateException: error al obtener el espacio de campo de la fila 0 col -1

My code is here :

c2=sql.dis();
c2.moveToFirst();
name = c2.getString(c2.getColumnIndex(DbManager.displayname));
ListName.setText("selected list"+name);
}

and this in BD class:

public Cursor dis() {

        try
        {
        SQLiteDatabase db= this.getWritableDatabase();
        String[] todo = new String[] {displayName };        
        Cursor cursor=db.query(displayname, todo, null, null, null,null, null);
        return cursor;
        }
        catch(Exception ex)
        {
            str = ex.toString();
        }

preguntado el 31 de enero de 12 a las 08:01

check cursor length and also if it is null or not. cursor.movetofirst should solve this problem but also use them -

@ Abhinav Singh Maurya thanks for ur comment just catch my mistake im using table name instead of column ** name = c2.getString(c2.getColumnIndex(DbManager.displayname));** displayname its table not column. now its working :) -

Thanks @android-xx for pointing that out actually I gave answer by seeing exception thats why I comment it not post as an answer I was just asking if that is helping out or not. Well congrats that you solved it out -

either delete the question or answer by yourself and accept it !! -

1 Respuestas

problem of above code is in this line name = c2.getString(c2.getColumnIndex(DbManager.displayname)); nombre para mostrar is table name not a column name.

Respondido el 08 de junio de 13 a las 10:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.