我想检查一下我的表是否有记录。这是我尝试过的:
if( cursor != null ){
cursor.moveToFirst();
if (cursor.getInt(0) == 0) {
Toast.makeText(getBaseContext(), "No records yet!", Toast.LENGTH_SHORT).show();
}
}
日志猫 说:
CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
任何帮助表示赞赏。谢谢。
尝试这个
cursor.getCount();
如果游标检索数据计数,它将返回,如果给出 0,则表示没有数据
so
if(cursor != null && cursor.getCount()>0){
cursor.moveToFirst();
//do your action
//Fetch your data
}
else {
Toast.makeText(getBaseContext(), "No records yet!", Toast.LENGTH_SHORT).show();
return;
}
注意:即使你检查if( cursor != null )
执行任何查询后游标不会返回空值,因此执行此操作以检查游标中的数据计数
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)