Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android上执行isNull时删除LogCat CursorWindow错误_Android_Cursor - Fatal编程技术网

在Android上执行isNull时删除LogCat CursorWindow错误

在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

我在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));
}
但当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