Android - 'cursor.close()' 可能会产生 'java.lang.nullpointerexception'?

标签 android sqlite android-cursoradapter

我有以下代码可以正常工作,但会产生警告:

method invocation 'cursor.close()' may produce 'java.lang.nullpointerexception'

code with warning

最佳答案

cursor_id 可能未初始化,例如,您的 try block 检查。您需要在 finally block 中添加相同的验证:

} finally { 
    if (cursor_id != null) {
        cursor_id.close();
    }
}

关于Android - 'cursor.close()' 可能会产生 'java.lang.nullpointerexception'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29507404/

相关文章:

android - 如何防止数字在我的 TextView 中转为科学记数法?

Android 使用 CursorAdapter 保存和恢复列表状态

android - 将变量传递到 Android 中游标适配器的绑定(bind) View

java - Android Edittext 的起始值不能是我数组中的第一个项目(Edittext Spinner)

android - 目标 SDK 越低,API 调用越多

c - 从 sqlite 表中的行中删除重复元素

iphone - SQLite ANALYZE 破坏索引

python - 插入 SQLite 数据库的行数为负数

android - 扩展 cursorAdapter,使用什么构造函数

java - ClassName.class.getResourceAsStream 返回 Null