出现空指针异常错误。错误行是 if (!temp4.equals(null)) {
。
我想在转换为数组时删除数据库中的空数据。请帮我。
String[] celement4array=new String[cc.getCount()];
int b=0;
for (cc.moveToFirst(); !cc.isAfterLast(); cc.moveToNext()) {
String temp4 = cc.getString(cc.getColumnIndex("element4"));
if (!temp4.equals(null)) {
celement4array[b]=temp4;
b++;
}
}
最佳答案
使用temp4 != null
。调用 .equals()
尝试使用该对象,该对象为 null
。
== 运算符以及 != 运算符返回 true 或 false,具体取决于要比较的两个元素的内存位置。当您想知道对象的内存位置是否不存在(null)时,可以使用 != 运算符。
关于java - 删除空数据时出现 nullpointerException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18542911/