捕获或异常为null [英] Caught Throwable or Exception is null

查看:800
本文介绍了捕获或异常为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在这里被问了两次,从来没有任何答案。或者答案是:这是不可能的!对不起,这可能太多了:

  try {
...
//行导致错误
LinearLayout cell =(LinearLayout)inflater.inflate(R.layout.channels_list_cell,column);
...
}
catch(Throwable e){
Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show(); <断点在这里
}

在断点e为空。请问如何寻找错误?很可能它不是java或Android的问题,而是Eclipse调试器,它本身需要很好的调试。但是我要做什么,除了改用不同的IDE?有任何想法吗?事先感谢。



我尝试过Throwable,异常,RuntimeException。结果是一样的。



尝试超越断点会导致NullPointerException,所以e似乎在那一刻真的是空的。哪里可以丢失?



编辑:
我向每个人都表示感激,并向每个回答者+1。这是一个Eclipse bug。重新启动Eclipse后,Exception不再为空,它是一个正常的RuntimeException:二进制XML文件行#15:您必须提供一个layout_width属性。

解决方案

您是否验证了 e 实际上是否为null?即如果(e == null)Log.d(异常为null),则添加类似的内容。然后,我将检查在正常执行期间和调试期间是否触发日志语句。如果两者之间的结果不同,则会显示VM错误(不太可能,但可能)。如果消息在任一情况下都没有被触发,那么可能是一个调试器问题。



有一些想法可以尝试调试问题: p>


  • 尝试像jdb一样,看看你是否有相同的行为


  • 您可以在调试器和设备之间获取jdwp通信的转储,并查看该级别发生了什么。可能使用wireshark或tcpdump,并将数据通过usb总线访问设备。


  • 您可以尝试将一些调试语句添加到dalvik本身。例如。获取AOSP的副本并构建一个模拟器映像,然后向dalvik添加一些调试语句,以尝试跟踪发生了什么。


  • 您可以尝试使用设备进行某种脚本化的jdwp会话


  • 您可以查看字节码(baksmali / dexdump / dedexer),看看有没有什么好笑的



A similar question was asked here for two times and never there was any answer. Or the answer was: "it is impossible!" Sorry, it is possible too much:

try{
    ...
    // the line that causes the error
    LinearLayout cell = (LinearLayout) inflater.inflate(R.layout.channels_list_cell, column);
    ...
}
catch(Throwable e){
    Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); < breakpoint here!
}

At the breakpoint e is null. How can I seek for the error, please? Very possibly it is not the problem of java or Android, but of the Eclipse debugger, that itself needs debugging badly. But what have I to do, except changing to a different IDE? Any ideas? Beforehand grateful.

I have tried Throwable, Exception, RuntimeException. The result is the same.

An attempt to step over breakpoint causes NullPointerException, so, e seems really null at that moment already. Where could it be lost?

Edit: I bring my gratitudes to everybody and +1 to every answerer. It was an Eclipse bug. After restart Eclipse the Exception is not null anymore, it is a normal RuntimeException: Binary XML file line #15: You must supply a layout_width attribute. It would be another problem to be solved, but this one is solved.

解决方案

Have you verified whether e is actually null or not? I.e. by adding something like if (e == null) Log.d("Exception is null"). I would then check if the log statement gets triggered both during normal execution and while debugging. If the results are different between the two, it would indicate a VM bug (unlikely, but possible). If the message doesn't get triggered in either case, then it's likely a debugger issue.

A few thoughts on further things you can try to debug the issue:

  • Try something like jdb and see if you get the same behaviour

  • You could get a dump of the jdwp communications between the debugger and the device, and see what's going on at that level. Maybe use wireshark or tcpdump and grab the data going over the usb bus to the device.

  • You could try adding some debug statements to dalvik itself. E.g. grab a copy of AOSP and build an emulator image, and then add some debugging statements to dalvik to try and track down what's going on.

  • You could attempt to do some sort of scripted jdwp session with the device

  • You could look at the bytecode (baksmali/dexdump/dedexer), to see if anything looks funny

这篇关于捕获或异常为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆