Datenbank auslesen

M

MSeiz5

Neues Mitglied
9
Weiss einer warum das nicht geht?

Code:
public void onListItemClick(
ListView parent, View v,
int position, long id)
{   
    open_database_rw();

    Cursor cursor = db.query("tbl_homework", new String[] {"hw"}, 
            "_id = 1", null, null, null, null);

    int column = cursor.getColumnIndex("hw");
    String item = cursor.getString(column);

    Toast.makeText(this, item, Toast.LENGTH_SHORT).show();

}

Fehlermeldung: Errormessage: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
 
if (cursor != null) {
if (cursor.moveToFirst()) {
 
  • Danke
Reaktionen: MSeiz5
@Tom299
Vielen Dank für den Tipp!
cursor.moveToFirst(); hat das Problem behoben.
 

Ähnliche Themen

S
Antworten
33
Aufrufe
2.672
Sempervivum
S
H
Antworten
2
Aufrufe
1.311
Hcman
H
Zurück
Oben Unten