无法捕获NetworkOnMainThreadException [英] Can't Catch NetworkOnMainThreadException
问题描述
奇怪的是,我没有运气这个代码(通过我的TCP套接字发送和接收):
try
{
toServer.println(msg.trim());
resp = fromServer.readLine();
}
catch(android.os.NetworkOnMainThreadException nex)
{...在这里做某事...
Eclipse根本无法识别该异常,我从Android开发者网站复制异常类型 - 我很确定拼写正确..
有什么我不知道Java(也许),这使得这个异常不可取代?
谢谢,
R。
我刚刚在我的eclipse版本上测试了这个,它的工作原理很好..我想我会检查你使用的api版本看起来要抛出这个异常,你需要一个最小的api版本11.否则eclipse是怪?我所知道的是这段代码是正确的,应该执行没有任何问题。
I know what causes a NetworkOnMainThreadException, as well as how to fix it, but for the purposes of improving the development experience, I'd like to be able to catch the exception and at least log the event or alert the user (who is still the developer at this point)...
Strangely, I'm not having any luck with this code (which sends and receives over my TCP socket):
try
{
toServer.println (msg.trim());
resp = fromServer.readLine();
}
catch (android.os.NetworkOnMainThreadException nex)
{ ... do something here ... }
Eclipse doesn't recognize that exception at all, and I copy-pasta-ed the exception type from the Android Developer website -- I'm pretty sure I spelled it right...
Is there something I don't know about Java (perhaps) that makes this exception uncatchable??
Thanks, R.
Well I just tested this on my version of eclipse, and it works just fine.. I guess I would check which version of the api you are using? looks like to throw that exception you need a minimum api version 11. Otherwise perhaps eclipse is to blame? All I know is that this code is correct and should be executing without any issues.
这篇关于无法捕获NetworkOnMainThreadException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!