异常始终为NULL [英] Exception is always NULL
问题描述
为什么Android的捕获处理程序不初始化Exception对象?
Why will the Android "Catch" handler not initialize an Exception object?
当发生错误并且我的代码尝试初始化Exception对象时,它是总是 NULL。
When an error occurs and my code is trying to initialize an Exception object it is always NULL.
以上对我来说没有意义,因为异常应始终初始化Exception对象-期间。
The above doesn't make sense to me, because the exception should always initialize the Exception object - period. It should never be null if an error occurs.
对于Eclipse Android IDE / SDK,我还是一个新手,我确信我没有设置所有东西100 %。但是,在我看来,这种类型的功能应该一直有效,而不是在设置之后。
I am fairly new to the Eclipse Android IDE/SDK, and I am sure I don't have everything set up 100%. However, this type of functionality would seem to me that it should work all the time, not after being set up.
推荐答案
一个可能的原因是您正在尝试在主线程上建立网络连接,该连接在2.3.3 / Honeycomb之前可以正常工作(例如,SDK级别< 10),但将被抛出为
One possible cause is that you are trying to make a network connection on your main thread, which works fine pre-2.3.3/Honeycomb (SDK level < 10 for example) but will be thrown as an
android.os.NetworkOnMainThreadException
android.os.NetworkOnMainThreadException
自SDK级别10起。
检查此内容: http:// developer.android.com/reference/android/os/NetworkOnMainThreadException.html
问题是Eclipse并不真正了解此异常(因为它是根据不同的SDK级别有条件地抛出的,因此Eclipse可能无法获得此异常的正确实例,这说明了为什么您的异常对象始终为NULL)
The problem is that Eclipse doesn't really know about this exception (since it is conditionally thrown based on different SDK level so Eclipse probably can't get a correct instance of this exception, that explains why your exception object is always NULL)
解决方案:创建一个单独的线程或使用AsyncTask执行您的网络连接请求。
Solution: create a separate thread or use AsyncTask to perform your network connection request.
这篇关于异常始终为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!