this function in android seems not working, can anybody give me a explaination?
public long getDoneLength(int mixId, long startPos) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
long doneLength = 0;
Cursor cursor = db.rawQuery("select doneLength from fragment where mixId=? and startPos=?", new String[]{String.valueOf(mixId), String.开发者_高级运维valueOf(startPos)});
while (cursor.moveToFirst()) {
doneLength = cursor.getLong(0);
}
cursor.close();
return doneLength;
}
This looks like an infinite loop. You should do if (cursor.moveToNext()) {...}
, not while
.
cursor.moveToFirst should only be called once. If you wanna know if the cursor is empty use
cursor.isAfterLast()
Regards, Stéphane
精彩评论