不幸的是,在选择启动新活动的列表视图项时已停止

时间:2014-05-11 09:35:56

标签: java android

   05-11 05:27:07.932: D/AndroidRuntime(1297): Shutting down VM
05-11 05:27:07.932: W/dalvikvm(1297): threadid=1: thread exiting with uncaught exception (group=0x41465700)
05-11 05:27:08.112: E/AndroidRuntime(1297): FATAL EXCEPTION: main
05-11 05:27:08.112: E/AndroidRuntime(1297): android.os.NetworkOnMainThreadException
05-11 05:27:08.112: E/AndroidRuntime(1297):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at libcore.io.IoBridge.connect(IoBridge.java:112)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at java.net.Socket.connect(Socket.java:842)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at com.example.carrentaladmin.AdminJSONParser.makeHttpRequest(AdminJSONParser.java:62)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at com.example.carrentaladminhonda.EditHondaActivity$GetProductDetails$1.run(EditHondaActivity.java:134)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at android.os.Handler.handleCallback(Handler.java:730)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at android.os.Looper.loop(Looper.java:137)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at android.app.ActivityThread.main(ActivityThread.java:5103)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at java.lang.reflect.Method.invokeNative(Native Method)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at java.lang.reflect.Method.invoke(Method.java:525)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-11 05:27:08.112: E/AndroidRuntime(1297):     at dalvik.system.NativeStart.main(Native Method)

我是Android开发的初学者,我完全不了解这些错误日志。我需要你们帮帮忙。希望你们能帮助我解决这个问题。

1 个答案:

答案 0 :(得分:3)

在android中,在您的活动的主线程上进行网络相关操作并不是一个好习惯。

为了做这些事情,还有其他方法,比如使用AsyncTask。