我需要检查列值是否为空。 documentation says :如果指示列中的值为 null,则 isNull 返回 TRUE。
因此,我尝试在代码中实现此功能:
if (c.isNull(c.getColumnIndex("description")))
description.setText("The column is null");
else
description.setText(c.getString(c.getColumnIndex("description")));
但即使该列为空,我也不会在条件中得到 true
。为什么会发生这种情况?
谢谢。
最佳答案
int index = c.getColumnIndex("description");
String str = c.getString(index);
if (str == null || str.isEmpty() || str.equalsIgnoreCase("null")) {
description.setText("Empty!");
} else {
description.setText(str);
}
关于android - 如何检查Cursor的空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25836883/