例外的是NULL永远 [英] Exception is NULL always

查看:117
本文介绍了例外的是NULL永远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能向我解释为什么Android的抓的处理程序不会初始化一个例外对象?当错误发生时,我的code正试图初始化一个异常对象时,它始终为空。

Can someone explain to me why the Android "Catch" handler will not initialize an Exception object? When an error occurs and my code is trying to initialize an Exception object it is ALWAYS NULL.

以上没有任何意义,我因为异常应该总是初始化异常对象的时期。如果发生错误,它不应该是空的。

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的Andr​​oid的IDE / SDK,我相信我没有一切设定的100%。然而,这种类型的功能,似乎对我来说,它应该工作的时候,不被设置后。

I am fairly new to the Eclipse Android IDE/SDK and I am sure I don't have everything setup 100%. However, this type of functionality would seem to me that it should work all the time, not after being setup.

推荐答案

一个可能的原因是,你试图让你的主线程,其工作方式的网络连接罚款pre-2.3.3 /蜂窝(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级。

检查:<一href="http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html">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屋!

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