异常总是NULL [英] Exception is NULL always
问题描述
上面对我来说没有意义,因为异常应该始终初始化异常对象期限。如果发生错误,它不应该为null。
我对Eclipse Android IDE / SDK相当新鲜,我相信我没有100%的设置。但是,这种类型的功能在我看来应该是所有的时间,而不是在设置之后。
原因是您正在尝试在主线程上建立网络连接,这在2.3.3 / Honeycomb(例如SDK级别< 10)之前工作正常,但将被抛出为
android.os.NetworkOnMainThreadException
自SDK级别为10。
检查: http://开发人员.android.com / reference / android / os / NetworkOnMainThreadException.html
问题是Eclipse并不知道这个异常(因为它是有条件地抛出基于不同的SDK级别,所以Eclipse可能无法得到这个异常的正确实例,这就解释了为什么你的异常对象总是为空)
解决方案:创建一个单独的线程或使用AsyncTask来执行网络连接请求。
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.
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.
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
since SDK level 10.
Check this: http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
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)
Solution: create a separate thread or use AsyncTask to perform your network connection request.
这篇关于异常总是NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!