这行代码有问题,getInt 方法上的编译器错误。因为变量 KEY_HITS 是 String 而不是 int。我该如何解决这个问题?
total = total + c.getInt(KEY_HITS);
这是更多代码;
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;
}