【发布时间】:2011-09-07 09:21:03
【问题描述】:
今天早上我遇到了一个奇怪的错误NullPointerException
String a,b;
a = this.getA();
b = this.getB();
if(a == null || a.equals(""))
a = "unknown a";
if(b == null || b.equals(""))
b = "unknown b";
System.out.println("a = " + a + " & " + "b = " b);
// the output is : a = a & b = unknown b
process(a,b); // The error occure here
此时我得到:Exception in thread "main" java.lang.NullPointerException
这里有什么问题?!
【问题讨论】:
-
请发布您的真实代码,并指出错误所在的行。 (字符串没有
eqauls方法。)实际的堆栈跟踪(至少是它的顶部)可能很有用。 -
从哪里得到 NullPointerException? println 消息告诉你什么?当您使用调试器单步执行代码时,您会看到什么?
-
编译吗?
eqauls()不存在。 -
你说错误发生在进程中,所以给我们看进程中的代码。
-
A NullPointerException 不是一个奇怪的错误。这将是最容易理解和调试的错误之一。
标签: java string exception nullpointerexception