在Android上执行isNull时删除LogCat CursorWindow错误
我在Android应用程序上使用了DAO方法,数据库对象被转换为java对象,如下所示:在Android上执行isNull时删除LogCat CursorWindow错误,android,cursor,Android,Cursor,我在Android应用程序上使用了DAO方法,数据库对象被转换为java对象,如下所示: public void populateObjectWithCursor(Cursor cursor) { if(!cursor.isNull(cursor.getColumnIndex(Const.USER_ID))) this.id = cursor.getLong(cursor.getColumnIndex(Const.USER_ID)); } 但当isNul
public void populateObjectWithCursor(Cursor cursor) {
if(!cursor.isNull(cursor.getColumnIndex(Const.USER_ID)))
this.id = cursor.getLong(cursor.getColumnIndex(Const.USER_ID));
}
但当isNull无法访问列时,它在logcat中显示错误:
E/CursorWindow:无法从CursorWindow读取第0行第1列
它有1行2列
我想了解一下,你知道这是否可能吗?没有发现任何异常来处理它
谢谢出现错误是因为
getColumnIndex(字符串名称)
方法正在为getLong(int columnName)
返回-1作为列索引。当提供的列名不存在时,该方法返回-1作为索引。因此,请使用getColumnName(int columnIndex)
方法检查列名,并在getColumnIndex(String columnName)
方法中使用相应的返回列名,而不是Const.USER\u ID
。这应该可以解决错误。感谢您的回复,像我之前编辑的帖子那样做可以解决我的问题。您的第二种方法解决了错误吗?如果是,请删除问题的答案。对于下一个对此感兴趣的人(感谢@Osama):public void populateObjectWithCursor(Cursor Cursor){int rowNumber=Cursor.getColumnCount();For(int i=0;i