Android在用运行app的时候直接崩掉,出现这些错误 5C

12-30 02:44:28.058: E/AndroidRuntime(2071): FATAL EXCEPTION: main
12-30 02:44:28.058: E/AndroidRuntime(2071): java.lang.RuntimeException: Unable to create application com.way.chat.activity.MyApplication: android.os.NetworkOnMainThreadException
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4394)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.os.Looper.loop(Looper.java:137)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-30 02:44:28.058: E/AndroidRuntime(2071): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 02:44:28.058: E/AndroidRuntime(2071): at java.lang.reflect.Method.invoke(Method.java:511)
12-30 02:44:28.058: E/AndroidRuntime(2071): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-30 02:44:28.058: E/AndroidRuntime(2071): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-30 02:44:28.058: E/AndroidRuntime(2071): at dalvik.system.NativeStart.main(Native Method)
12-30 02:44:28.058: E/AndroidRuntime(2071): Caused by: android.os.NetworkOnMainThreadException
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
12-30 02:44:28.058: E/AndroidRuntime(2071): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
12-30 02:44:28.058: E/AndroidRuntime(2071): at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
12-30 02:44:28.058: E/AndroidRuntime(2071): at libcore.io.IoBridge.connect(IoBridge.java:112)
12-30 02:44:28.058: E/AndroidRuntime(2071): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
12-30 02:44:28.058: E/AndroidRuntime(2071): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
12-30 02:44:28.058: E/AndroidRuntime(2071): at java.net.Socket.connect(Socket.java:842)
12-30 02:44:28.058: E/AndroidRuntime(2071): at com.way.client.Client.start(Client.java:28)
12-30 02:44:28.058: E/AndroidRuntime(2071): at com.way.chat.activity.MyApplication.onCreate(MyApplication.java:29)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
12-30 02:44:28.058: E/AndroidRuntime(2071): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
12-30 02:44:28.058: E/AndroidRuntime(2071): ... 10 more

(需要代码的可以私我)

0

13个回答

android.os.NetworkOnMainThreadException网络请求放在主线程中进行了,网络请求不能再主线程发起请求,必须new Runnable,在这个子线程中发起

0

把下载操作放到子线程中

0

不要在主线程中进行一些耗时操作,network操作也包含在内

0

主线程不应该操作网络请求,task去执行,或者直接加入第三方框架去做网络请求

0

java.lang.RuntimeException: Unable to create application com.way.chat.activity.MyApplication: android.os.NetworkOnMainThreadException
请求网络是耗时操作,你在主线程执行,会阻塞线程的,需要把请求网络等耗时操作放在子线程执行,new Tread(new Runnable(){ }).start();

0

网络操作不能放在主线程里面,

参考一下:

 http://blog.csdn.net/guolin_blog/article/details/17482095
0

不能放在主线程中。。。。

0

android在4.x之后就规定在主线程中不能做网络操作,必须要开启新的线程,在正常情况是,我们也会将网络请求,文件操作等耗时操作放在子线程中进行处理,以免主线程中UI的刷新的阻碍

0

NetworkOnMainThreadException是因为你的网络操作放在了主线程中运行,可以开启子线程把网络操作放在里面运行就可运行了。

0

NetworkOnMainThreadException 网络操作属于耗时操作,不应该放在主线程中执行

0
共13条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!