Logcat Null检查返回误报

时间:2013-04-18 08:44:39

标签: java android logcat

我正在做一个简单的测试(尝试无效检查一个值)而且只是为了踢,我决定无效检查一个make believe / nonexistant值:" striiing"在我的源代码中的任何地方都不存在。然后我检查了我的logcat并意识到这个不存在的值显示为:

04-18 04:40:22.197: D/com.game.demo.Level1(15800): Broken Value! Debug! Debug!
执行以下操作时

 if ("striiing" != null) {
            Log.d(TAG, "Broken Value! Debug! Debug!");
 prefs.getBoolean("name", true);
 prefs.getBoolean("player", true);
 prefs.getBoolean("points", true);
 prefs.getBoolean("level", true);
 prefs.getBoolean("gear", true);

有人可以解释为什么不存在的值可能/会显示为非null吗?这很奇怪。

1 个答案:

答案 0 :(得分:0)

"striiing"是一个String文字,它是Java中的非null对象。试试这个:

String s = null;
if (s == null) ...

它应该按预期工作。

相关问题