由於某些原因,在Android清單文件中添加uses-sdk字段會導致崩潰。我以前沒有發生過這種情況,但現在我無法擺脫它。在Android清單文件中添加uses-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或任何真正的早期級別),如果uses-sdk子句在文件中,應用程序將崩潰。
刪除它允許它運行。
我得到的錯誤是「不幸的[app]已經停止」默認,並且logcat列表中存在關聯的「FATAL EXCEPTION:main」錯誤。
任何幫助或建議表示讚賞。
謝謝!
這是我正在努力的一本書的例子(或者我應該說)。 :)
我在下面添加完整的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
如果您添加完整的錯誤日誌,這將有所幫助。刪除uses-sdk絕對不是要走的路。您應該始終定義最低版本和目標版本(通常是最後一個版本) – Teovald
我已經從logcat輸出添加了完整列表。這很令人困惑。我從來沒有遇到過任何我嘗試過的例子的問題,但我不確定爲什麼這會導致如此簡單的問題。 – Zeus56