I am having an issue where my cursor's respective while loop is not running. Cursor.columncount() always returns 1. Are there any errors in how I increment my cursor? A Pictoral View (Column returned): |Rating| |2 | |3 | |6 | -->Function should return 11/3 (3.66666)
public double getAverageRating(String title) {
title = title.toUpperCase();
int rating = 0;
int count = 1;
SQLiteDatabase db = this.getReadableDatabase();
String str = "SELECT RATING FROM " + TABLE_NAME + " WHERE TITLE=" + "'" + title + "'" + ";";
Cursor cur = db.rawQuery(str, null);
while(cur.moveToNext()) {
int b = Integer.parseInt(cur.getString(cur.getColumnIndex("RATING")));
rating += b;
count++;
}
cur.close();
return (double) rating/count;
//return rating;
}
Aucun commentaire:
Enregistrer un commentaire