1

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.

1 Answer 1

1

You're closing the cursor then returning it. You probably want to return the column total or sum total, not the cursor

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.