开发者

this function in android seems not working, can anybody give me a explaination?

开发者 https://www.devze.com 2023-03-13 12:51 出处:网络
public long getDoneLength(int mixId, long startPos) { SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
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

0

精彩评论

暂无评论...
验证码 换一张
取 消