android.os.NetworkOnMainThreadException 如何解决

wffger 发布于 2014/06/15 12:40
阅读 1K+
收藏 0
06-15 12:39:52.554 22666-22666/com.qrbike.app W/System.err﹕ android.os.NetworkOnMainThreadException 06-15 12:39:52.556 22666-22666/com.qrbike.app W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128) 06-15 12:39:52.557 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 06-15 12:39:52.559 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 06-15 12:39:52.559 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214) 06-15 12:39:52.560 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70) 06-15 12:39:52.562 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 06-15 12:39:52.563 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340) 06-15 12:39:52.563 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87) 06-15 12:39:52.564 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 06-15 12:39:52.565 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316) 06-15 12:39:52.566 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.connect(HttpEngine.java:311) 06-15 12:39:52.567 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290) 06-15 12:39:52.567 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240) 06-15 12:39:52.568 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81) 06-15 12:39:52.569 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:205) 06-15 12:39:52.570 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126) 06-15 12:39:52.570 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185) 06-15 12:39:52.570 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.common.SoapHelper.callWebService(SoapHelper.java:68) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.Upload.upload2DB(Upload.java:50) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.BackupList$1$1.onClick(BackupList.java:80) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169) 06-15 12:39:52.571 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99) 06-15 12:39:52.572 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Looper.loop(Looper.java:153) 06-15 12:39:52.572 22666-22666/com.qrbike.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5449) 06-15 12:39:52.572 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method) 06-15 12:39:52.572 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511) 06-15 12:39:52.572 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:835) 06-15 12:39:52.573 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 06-15 12:39:52.573 22666-22666/com.qrbike.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method) 06-15 12:39:52.573 22666-22666/com.qrbike.app I/System.out﹕ [CDS] fix other exception in HttpUrlConnection 06-15 12:39:52.573 22666-22666/com.qrbike.app W/System.err﹕ java.io.IOException 06-15 12:39:52.573 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:87) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:205) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113) 06-15 12:39:52.574 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.common.SoapHelper.callWebService(SoapHelper.java:68) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.Upload.upload2DB(Upload.java:50) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.BackupList$1$1.onClick(BackupList.java:80) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Looper.loop(Looper.java:153) 06-15 12:39:52.575 22666-22666/com.qrbike.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5449) 06-15 12:39:52.576 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method) 06-15 12:39:52.576 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511) 06-15 12:39:52.576 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:835) 06-15 12:39:52.576 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 06-15 12:39:52.577 22666-22666/com.qrbike.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method) 06-15 12:39:52.590 22666-22666/com.qrbike.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1664K (4892), 33% free 4439K/6600K, paused 11ms, total 13ms 06-15 12:39:52.593 22666-22666/com.qrbike.app W/System.err﹕ android.os.NetworkOnMainThreadException 06-15 12:39:52.594 22666-22666/com.qrbike.app W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128) 06-15 12:39:52.594 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87) 06-15 12:39:52.595 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 06-15 12:39:52.596 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316) 06-15 12:39:52.596 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.connect(HttpEngine.java:311) 06-15 12:39:52.596 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290) 06-15 12:39:52.596 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:205) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118) 06-15 12:39:52.597 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.common.SoapHelper.callWebService(SoapHelper.java:68) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.Upload.upload2DB(Upload.java:50) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.BackupList$1$1.onClick(BackupList.java:80) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Looper.loop(Looper.java:153) 06-15 12:39:52.598 22666-22666/com.qrbike.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5449) 06-15 12:39:52.599 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method) 06-15 12:39:52.599 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511) 06-15 12:39:52.599 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:835) 06-15 12:39:52.599 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 06-15 12:39:52.599 22666-22666/com.qrbike.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method) 06-15 12:39:52.599 22666-22666/com.qrbike.app I/System.out﹕ [CDS] fix other exception in HttpUrlConnection 06-15 12:39:52.600 22666-22666/com.qrbike.app W/System.err﹕ java.io.IOException 06-15 12:39:52.600 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:87) 06-15 12:39:52.600 22666-22666/com.qrbike.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:205) 06-15 12:39:52.600 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126) 06-15 12:39:52.601 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.common.SoapHelper.callWebService(SoapHelper.java:68) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.Upload.upload2DB(Upload.java:50) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at com.qrbike.app.ui.BackupList$1$1.onClick(BackupList.java:80) 06-15 12:39:52.602 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at android.os.Looper.loop(Looper.java:153) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5449) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511) 06-15 12:39:52.603 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:835) 06-15 12:39:52.604 22666-22666/com.qrbike.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 06-15 12:39:52.604 22666-22666/com.qrbike.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method) 06-15 12:39:52.604 22666-22666/com.qrbike.app D/OpenGLRenderer﹕ Flushing caches (mode 0) 06-15 12:39:52.657 22666-22666/com.qrbike.app V/InputMethodManager﹕ onWindowFocus: android.widget.ListView{41de9010 VFED.VC. .F...... 0,0-720,1134 #7f070049 app:id/files} softInputMode=16 first=false flags=#1810100
加载中
0
fneg
fneg

不要将网络操作放在主线程里面,在线程里面获取网络数据,然后通过handler解决

0
nevans
nevans
Netroid,你值得拥有。
0
返回顶部
顶部