开发者

catching null exception [duplicate]

This question already has answers here: 开发者_StackOverflow社区 try catch exception always returns null (4 answers) Closed 9 years ago.

I'm working on a java application for android and I currently am getting a problem where the debugger is stepping into my catch block and somehow ex is null? Has anyone seen anything like this before?

}
catch(Exception ex)
{
   // Debugger is coming through the catch block and ex is null ????
}


This sounds like the source code and the compiled classes are out of sync, so the debugger is stepping into the wrong block.

Try to do a clean and then a rebuild.


The exception will never be null in that block. If the instruction pointer in the debugger is pointing at the catch line, you need to step one more line to get the exception to be accessible to you. You may want to add a line of code (potentially a log call) to your catch block and put your break point on that to catch what ex is.


Add some log statements and check. Your ex may be out of scope.


I had exactly the same problem inside an AsyncTask, while debugging on a real device (Galaxy Tab 2). So I too can confirm, that this strange problem is real.

For me the accepted answer didn't help.

But in my case the problem mysteriously went away after unplugging the usb plug of the device and connecting it again afterwards (and then running my app again).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜