0

having problem with this line of code, compiler error on getInt method. because the variable KEY_HITS is a String and not an int. How do I fix this problem?

 total = total + c.getInt(KEY_HITS);

here is more of the code;

    public static final String KEY_ROWID="_id";
    public static final String KEY_NAME="persons_name";
    public static final String KEY_HITS="persons_hits";

 public int getTotal() {

String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_HITS };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
        null, null);
int total = 0;

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
    total = total + c.getInt(KEY_HITS);
}
return total;
 }

1 Answer 1

1

Do what errors says because the variable KEY_HITS is a String and not an int
you need to pass integer parameter in getInt(). You can get column's index by getColumnIndex()

total = total + c.getInt(c.getColumnIndex(KEY_HITS));
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.