开发者社区 问答 正文

androidSQLite检测表是否有数据

如题,我想检测表是不是有数据,代码如下:

if( cursor != null ){
        cursor.moveToFirst();
        if (cursor.getInt(0) == 0) {
        Toast.makeText(getBaseContext(), "No records yet!", Toast.LENGTH_SHORT).show();
        }
    }

logcat如下:
CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
请指教,谢谢。

展开
收起
a123456678 2016-07-18 13:56:03 1931 分享 版权
1 条回答
写回答
取消 提交回答
  • if(cursor.moveToFirst()){
    //do your work
    }
    else{
    Toast.makeText(getBaseContext(), "No records yet!", Toast.LENGTH_SHORT).show();
    }

    2019-07-17 19:57:47
    赞同 展开评论
问答地址: