我的程序正在從Android 2.1的精絕至Android 2.3應用程序不工作在Android 4.0
但它不工作的更高的安卓
版本我已經在我的清單文件中使用
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="10"
android:maxSdkVersion="15"/>
logcat的輸出誤差,同時運行該項目在Android 4.0.3 AVD結果
05-09 12時45分12秒.051:E/AndroidRuntime(530):致命異常:主' 05-09 12:45:12.051:E/AndroidRuntime(530):java.lang.RuntimeException: 無法啓動活動ComponentInfo {giv.home/giv .home.Start}: Android.os.NetworkOnMainThreadException 05-09 12:45:12.051: E/AndroidRuntime(530):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 05-09 12 :45:12.051:E/AndroidRuntime(530):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 05-09 12:45:12.051:E/AndroidRuntime(530):at android.app .ActivityThread.access $ 600(ActivityThread.java:123)05-09 12:45:12.051:E/AndroidRuntime(530):at android.app.ActivityThre ad $ H.handleMessage(ActivityThread.java:1147) 05-09 12:45:12.051:E/AndroidRuntime(530):at android.os.Handler.dispatchMessage(Handler.java:99)05-09 12 :45:12.051:E/AndroidRuntime(530):at android.os.Looper.loop(Looper.java:137)05-09 12:45:12.051: E/AndroidRuntime(530):at android.app .ActivityThread.main(ActivityThread.java:4424)05-09 12:45:12.051:E/AndroidRuntime(530):at java.lang.reflect.Method.invokeNative(Native Method)05-09 12:45 :12.051:E/AndroidRuntime(530):at java.lang.reflect.Method.invoke(Method.java:511)05-09 12:45:12.051: E/AndroidRuntime(530):at com.android .internal.os.ZygoteInit $ MethodAn dArgsCaller.run(ZygoteInit.java:784) 05-09 12:45:12.051:E/AndroidRuntime(530):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)05-09 12:45:12.051:E/AndroidRuntime(530):at dalvik.system.NativeStart.main(本機方法)05-09 12:45:12.051: E/AndroidRuntime(530):引起: android。 os.NetworkOnMainThreadException 05-09 12:45:12.051: E/AndroidRuntime(530):at android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 05-09 12:45:12.051:E/AndroidRuntime(530):at java.net.InetAddress.lookupHostByName(InetAddress.java:391)05-09 12:45:12.051:E/AndroidRuntime(530):at java.net.I netAddress.getAllByNameImpl(InetAddress.java:242)05-09 12:45:12.051:E/AndroidRuntime(530):at java.net.InetAddress.getAllByName(InetAddress.java:220)05-09 12:45 :12.051:E/AndroidRuntime(530):at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) 05-09 12:45:12.051:E/AndroidRuntime(530):at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 05-09 12:45:12.051:E/AndroidRuntime(530):at org.apache.http.impl.conn。 AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 05-09 12:45:12.051:E/AndroidRuntime(530):at org.apache.http.impl.client.DefaultRequestDirector。執行(DefaultRequestDirector.java:360) 05-09 12:45:12.051:E/AndroidRuntime(530):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 05- 09 12:45:12.051:E/AndroidRuntime(530):在 org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 十二月5日至9日:45:12.051:E/AndroidRuntime( 530):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 05-09 12:45:12.051:E/AndroidRuntime(530):at giv.home.ConnectionClass。 connectToServer(ConnectionClass.java:41) 十二月5日至9日:45:12.051:E/AndroidRuntime(530):在 giv.home.Start.onCreate(Start.java:64)十二月5日至9日:45:12.051: E/AndroidRuntime(530):at android.app.Activity.performCreate(Activity.java:4465)05-09 12:45:12.051:E/AndroidRuntime(530):at android.app.Instrumentation.callActivityOnCreate( Instrumentation.java:1049) 05-09 12:45:12.051:E/AndroidRuntime(530):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 05-09 12:45:12.051:E/AndroidRuntime(530):... 11更多
可能重複(HTTP ://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception) – laalto