我正在开发一个我在Android 2.3.3中开发的项目。
我想继续在Android 4.0.3上开发它,但它不起作用。
当我从清单文件中删除usesminsdk
时,它可以正常工作。
还有其他办法吗?我的方式健康吗?
06-19 09:19:33.122: E/AndroidRuntime(595): FATAL EXCEPTION: main
06-19 09:19:33.122: E/AndroidRuntime(595): android.os.NetworkOnMainThreadException
06-19 09:19:33.122: E/AndroidRuntime(595): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
06-19 09:19:33.122: E/AndroidRuntime(595): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
06-19 09:19:33.122: E/AndroidRuntime(595): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
06-19 09:19:33.122: E/AndroidRuntime(595): at java.net.InetAddress.getAllByName(InetAddress.java:220)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
06-19 09:19:33.122: E/AndroidRuntime(595): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.facebook.android.Util.openUrl(Util.java:215)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.facebook.android.Facebook.request(Facebook.java:751)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.facebook.android.Facebook.request(Facebook.java:688)
06-19 09:19:33.122: E/AndroidRuntime(595): at tr.edu.ege.yanyanayiz.LoginController.getProfileInformation(LoginController.java:116)
06-19 09:19:33.122: E/AndroidRuntime(595): at tr.edu.ege.yanyanayiz.LoginController.startNewIntent(LoginController.java:50)
06-19 09:19:33.122: E/AndroidRuntime(595): at tr.edu.ege.yanyanayiz.LoginController$2.onComplete(LoginController.java:95)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.facebook.android.Facebook$1.onComplete(Facebook.java:354)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:144)
06-19 09:19:33.122: E/AndroidRuntime(595): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
06-19 09:19:33.122: E/AndroidRuntime(595): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:324)
06-19 09:19:33.122: E/AndroidRuntime(595): at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 09:19:33.122: E/AndroidRuntime(595): at android.os.Looper.loop(Looper.java:137)
06-19 09:19:33.122: E/AndroidRuntime(595): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-19 09:19:33.122: E/AndroidRuntime(595): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 09:19:33.122: E/AndroidRuntime(595): at java.lang.reflect.Method.invoke(Method.java:511)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 09:19:33.122: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-19 09:19:33.122: E/AndroidRuntime(595): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:4)
我今天早上写了一篇关于完全相同主题的博客文章。在滥用UI线程时,HoneyComb和ICS要严格得多。检查您是否在UI线程上没有执行任何昂贵的操作,如果您将它们包裹在Thread
或AsyncTask
中。
答案 1 :(得分:3)
我也遇到了这个问题。我有两种方法可以逃避它: 1.将网络代码放入另一个线程,以避免NetworkOnMainThreadException 2.将AndroidManifest.xml从A)修改为B):
A)
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="10" />
B)
<uses-sdk
android:minSdkVersion="7"
/>
现在它有效!
答案 2 :(得分:1)
确保您的清单标记如下:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
然后
你应该好好去,但你可能需要清理项目或右键单击项目&gt; Android工具&gt;之后修复项目属性。
答案 3 :(得分:0)
您好,我想这是因为您在主UI线程中访问网络(也检查您的web服务)在您的代码中使用AsyncTask并且错误将不会成为清单文件的问题而无需在Manifest中更改任何内容。< / p>