android中的这个功能似乎不起作用,任何人都可以给我一个解释吗?

时间:2011-06-16 02:08:22

标签: android sqlite

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;
}

2 个答案:

答案 0 :(得分:1)

这看起来像一个无限循环。您应该if (cursor.moveToNext()) {...},而不是while

答案 1 :(得分:0)

cursor.moveToFirst只应调用一次。如果您想知道光标是否为空,请使用

cursor.isAfterLast() 

此致  斯特凡

相关问题