我在写一个欢迎界面的时候,报了下面的错误,感觉很奇怪。明明是在线程中访问了网络,怎么还会报这个错误05-2221:42:32.85515254-15254/com.zhu.teacherhelperE/AndroidRuntime﹕FATALEXCEPTION:mainProcess:com.zhu.teacherhelper,PID:15254android.os.NetworkOnMainThreadExceptionatandroid.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)atlibcore.io.BlockGuardOs.sendto(BlockGuardOs.java:276)atlibcore.io.IoBridge.sendto(IoBridge.java:513)atjava.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)atjava.net.DatagramSocket.send(DatagramSocket.java:305)atcom.zhu.teacherhelper.utils.ServerAddressUtils.AskServerAddress(ServerAddressUtils.java:39)atcom.zhu.teacherhelper.ui.WelcomeActivity$AskServerIP.run(WelcomeActivity.java:31)atandroid.os.Handler.handleCallback(Handler.java:739)atandroid.os.Handler.dispatchMessage(Handler.java:95)atandroid.os.Looper.loop(Looper.java:135)atandroid.app.ActivityThread.main(ActivityThread.java:5233)atjava.lang.reflect.Method.invoke(NativeMethod)atjava.lang.reflect.Method.invoke(Method.java:372)atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)代码如下:@OverrideprotectedvoidonCreate(BundlesavedInstanceState){requestWindowFeature(Window.FEATURE_NO_TITLE);super.onCreate(savedInstanceState);setContentView(R.layout.activity_welcome);Handlerhandler=newHandler();//延迟一秒后进行handler.postDelayed(newAskServerIP(),1000);}classAskServerIPimplementsRunnable{@Overridepublicvoidrun(){//获取服务器ip地址ServerAddressUtils.AskServerAddress(getApplicationContext());Intentintent=newIntent(WelcomeActivity.this,MouseActivity.class);startActivity(intent);WelcomeActivity.this.finish();}}
慕田峪7331174
有只小跳蛙
相关分类