java - SqLite: Cursor does not increment correctly -
i having issue cursor's respective while loop not running. cursor.columncount() returns appropriate amount of columns. there errors in how increment 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 " + table_name + " 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; }
Comments
Post a Comment