I have what seems like a very simple method, written in java for an android application:
EDIT 1: private String newResponse;
public SOME METHOD CALLED FIRST
{
newResponse = "";
}
END OF EDIT 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();
}
}
When I run the application in debugger mode, it 'suspends' on the line:
newResponse = newResponse + message;
It says in the debug window:
Thread[<9> Thread-10] (Suspended (exception NullPointerException))
This occurs only some of the time. Sometimes it runs the line fine.
It never goes into the catch clause and when you click continue, the app crashes. There isn't a break point on the line so I don't even know why it is suspending there.
newResponse is of type String, defined as a global variable.
Can anyone help?
Try above code..
I have fixed the problem.
For anyone wondering, I added
before
And that prevents the error.
Thanks for everyone's help.
Inspect the individual variables to see which one is null.
Also,
e.getCause()
may be returning null also, so you may have an exception inside your exception handler as well.