我有一个看起来非常简单的方法,是用 java 为 android 应用程序编写的:
编辑 1: 私有(private)字符串 newResponse;
public SOME METHOD CALLED FIRST
{
newResponse = "";
}
编辑 1 结束
public synchronized void reportMessage(String message)
{
try
{
newResponse = newResponse + message;
confirmQE(); //Look for qe in the message
}
catch (Exception e)
{
response = e.getCause().toString();
}
}
当我在调试器模式下运行应用程序时,它在线上“暂停”:
newResponse = newResponse + message;
它在调试窗口中说:
Thread[<9> Thread-10](暂停(异常 NullPointerException))
这只会在某些时候发生。有时它运行良好。
它永远不会进入 catch 子句,当您单击继续时,应用程序会崩溃。线路上没有断点,所以我什至不知道它为什么卡在那里。
newResponse 是 String 类型,定义为全局变量。
有人可以帮忙吗?
最佳答案
try
{
// NOW add following condition and initialize newResponce only when it is null
if(null == newResponse)
{
newResponse = new String();
}
System.out.println("newResponse"+newResponse); //<--Add this two lines
System.out.println("message"+message); // and check which line gives you NullPointerException
newResponse = newResponse + message;
confirmQE(); //Look for qe in the message
}
关于java/android NullPointerException 在字符串上抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11613060/