user2960452
user2960452

Reputation: 41

SQLite fails to read row 0

So I am trying to return a string from an SQLite database - I've seen a few examples on here but no matter what I try it still crashes saying

Failed to read row 0, column 1 from a CursorWindow which has 1 rows, 1 columns.

To assign the result to a string I am using

String email = db.GetEmail();

The getEmail() function is as follows:

public String GetEmail(){
    SQLiteDatabase db = this.getReadableDatabase();
    String QueryText = "SELECT * FROM " + TABLE_LOGIN;
    Cursor cursor = db.rawQuery(QueryText,null);
    cursor.moveToFirst();


    if(cursor.isFirst()){
        String result = cursor.getString(1);
    return result;  
    }else{
        return "FALSE";
    }


}

Upvotes: 0

Views: 103

Answers (1)

bdn02
bdn02

Reputation: 1500

The error message explain the problem.

There is one column and column indices are 0-based. Try:

String result = cursor.getString(0); /* first column */

Upvotes: 4

Related Questions