Sqlite empty cursor error?

前端 未结 1 632
孤街浪徒
孤街浪徒 2021-01-28 22:16

Normaly, this code working very well. But, if \"cursor\" is empty, there is an error in main.class. I tried a lot of thing. But, I didn\'t success. Please help to solve way.

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 22:37

    If the cursor contains no data, moveToFirst() returns false. So add any special empty cursor handling to an else branch of your if (cursor.moveToFirst()) conditional in your first snippet:

    if (cursor.moveToFirst()) {
        do {
            list.add(Integer.parseInt(cursor.getString(1)));
        }
        while (cursor.moveToNext());
    } else {
        // whatever you'd like to do in case of no data
    }
    

    0 讨论(0)
提交回复
热议问题