添加使用-SDK领域机器人会在清单文件会导致崩溃(Adding the uses-sdk field

2019-08-01 03:07发布

出于某种原因,在Android的清单文件中添加使用-SDK字段时会导致崩溃。 我已经没有这种情况发生前,但我不能让现在摆脱它。

清单文件的相关部分如下:

android:versionName="1.0" >

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

<uses-permission android:name="android.permission.INTERNET"/>

<application

移动上述许可线,或低于用途-SDK子句都没有区别,也没有改变的最小或目标版本。 无论选择什么(在合理范围内,因为我不能回去API 8,或10,或任何真正的早期水平)的应用程序崩溃,如果使用-SDK条款是在文件中。

删除它允许它运行。

我得到的错误是“不幸的是[应用]已停止”默认并有相关的“致命异常:主要”在logcat中上市的错误。

任何帮助或建议表示赞赏。

谢谢!

这是一本书,我通过工作(或试图我应该说)的例子。 :)

我加入了完整的logcat下面的清单。

10-03 13:29:18.270: E/Trace(860): error opening trace file: No such file or directory (2)
10-03 13:29:18.950: D/AndroidRuntime(860): Shutting down VM
10-03 13:29:18.950: W/dalvikvm(860): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
10-03 13:29:18.960: E/AndroidRuntime(860): FATAL EXCEPTION: main
10-03 13:29:18.960: E/AndroidRuntime(860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.earthquake/com.paad.earthquake.Earthquake}: android.os.NetworkOnMainThreadException
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.os.Looper.loop(Looper.java:137)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread.main(ActivityThread.java:4745)
10-03 13:29:18.960: E/AndroidRuntime(860):  at java.lang.reflect.Method.invokeNative(Native Method)
10-03 13:29:18.960: E/AndroidRuntime(860):  at java.lang.reflect.Method.invoke(Method.java:511)
10-03 13:29:18.960: E/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-03 13:29:18.960: E/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-03 13:29:18.960: E/AndroidRuntime(860):  at dalvik.system.NativeStart.main(Native Method)
10-03 13:29:18.960: E/AndroidRuntime(860): Caused by: android.os.NetworkOnMainThreadException
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
10-03 13:29:18.960: E/AndroidRuntime(860):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
10-03 13:29:18.960: E/AndroidRuntime(860):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
10-03 13:29:18.960: E/AndroidRuntime(860):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
10-03 13:29:18.960: E/AndroidRuntime(860):  at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
10-03 13:29:18.960: E/AndroidRuntime(860):  at com.paad.earthquake.EarthquakeListFragment.refreshEarthquakes(EarthquakeListFragment.java:77)
10-03 13:29:18.960: E/AndroidRuntime(860):  at com.paad.earthquake.EarthquakeListFragment.onActivityCreated(EarthquakeListFragment.java:55)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:848)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1017)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1802)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.Activity.performCreate(Activity.java:5011)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-03 13:29:18.960: E/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-03 13:29:18.960: E/AndroidRuntime(860):  ... 11 more

Answer 1:

该错误NetworkOnMainThreadException与ICS开始,你不能在主线程上的任何网络接入。 你或许应该使用AsyncTask ,你做网络接入。



Answer 2:

作为@Sameer说,你在你活动的核心做网络电话。 你不应该这样做。 是用于UI的一个:您的活动的所有代码的主线程上运行。 你不应该作出该线程任何繁重的计算:它需要的资源远离UI,使其滞后。 因为你没有用户界面被阻止的响应,只要:HTTP调用更是雪上加霜。

实现一个的AsyncTask您的网络电话。



文章来源: Adding the uses-sdk fields in Androids manifest file causes crash