Reputation: 115
I need help with summing all the values in one of the columns(KEY_CONTENT6
) in my database(MYDATABASE_TABLE
). I keep having force close issues, somebody tell me what I'm doing wrong!
Heres my code:
public Cursor sumAll(){
float columntotal = 0;
Cursor cursor1 = sqLiteDatabase.rawQuery(
"SELECT SUM("+Float.valueOf(KEY_CONTENT6)+") FROM MYDATABASE_TABLE", null);
if(cursor1.moveToFirst()) {
columntotal = cursor1.getFloat(0);
}
cursor1.close();
String sumtotal = Float.toString((float)columntotal);
return cursor1;
}
The column KEY_CONTENT6
is a string for various reasons which is why I used Float.valueOf()
but I'm guessing that's where my problem is.
Upvotes: 1
Views: 3459
Reputation: 1764
You're closing the cursor then returning it. You probably want to return the column total or sum total, not the cursor
Upvotes: 1