2

我正在研究我在 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)
4

4 回答 4

4

为什么我的应用程序在冰淇淋三明治上崩溃?

我今天早上刚刚写了一篇关于完全相同主题的博客文章。HoneyComb 和 ICS 在滥用 UI 线程时要严格得多。检查您是否没有在 UI 线程上执行任何昂贵的操作,以及是否将它们包装在 aThread或 an中AsyncTask

于 2012-06-18T15:31:19.140 回答
3

我也遇到了这个问题。我有两种方法可以摆脱它: 1. 将网络代码放入另一个线程,以避免 NetworkOnMainThreadException 2. 将 AndroidManifest.xml 从 A) 修改为 B):

一个)

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="10" />

二)

<uses-sdk
android:minSdkVersion="7"
 />

现在它可以工作了!

于 2012-07-27T03:41:56.293 回答
1

确保您的清单标签是这样的:

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

然后

  1. 右键项目
  2. 特性
  3. 安卓
  4. 检查安卓 4.0.3
  5. 点击确定。

你应该很高兴,但之后你可能需要清理项目或右键单击项目 > Android 工具 > 修复项目属性。

于 2012-06-18T15:25:21.213 回答
0

嗨,我想这是因为您正在主 UI 线程中访问网络(同时检查您的 Web 服务)在您的代码中使用 AsyncTask,并且错误不会成为清单文件的问题,无需更改清单中的任何内容。

于 2012-09-26T12:45:27.873 回答