如何在表中统计 of 的行数?

我用下面的代码获取行数,但是程序被挂起。怎么回事呢?

private int countbaglist()
{
    int count = 0;
    SQLiteDatabase db = datasource.getWritableDatabase();
    Cursor cursor = db.rawQuery(
        "select count(*) from shoplist where itemname=?",
        new String[] { String.valueOf("itemname") });

    while(cursor.moveToFirst())
    {
        count = cursor.getCount();
    }
    return count;
}

程序被挂起没明白是什么意思,while(cursor.moveToFirst())只是想提醒下这里有隐患,cursor要是为空肯定会有异常,至于sql是否正确没有验证。