Reputation: 41
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
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