我遇到的问题是我的光标所在的while循环没有运行。 Cursor.columncount()返回适当数量的列。我如何增加光标有错误吗?
Pictoral View(返回列):
|Rating|
|2 |
|3 |
|6 |
函数应返回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;
}