tags:

views:

60

answers:

1
Cursor cursor = db.rawQuery("SELECT COUNT(rat) 
                               FROM "+ TABLE_NAME_EXTRA +" apkid=\""+apkid, null);
cursor.moveToFirst();
int somatotal = cursor.getInt(0);

I'm trying to do a SQL function like count and sum, but this code returns a exception saying "emptyvalues".

anyone know why?

A: 

You should use DatabaseUtils.longForQuery utility method to run the query on the db and return the value in the first column of the first row.

int sometotal=DatabaseUtils.longForQuery(db,"SELECT COUNT(rat) 
                               FROM "+ TABLE_NAME_EXTRA +" where apkid=\""+apkid+"\"",null);
Pentium10