我想只在版本ICS上运行我的应用程序

时间:2013-12-16 06:20:32

标签: android android-layout android-manifest android-version

我想在ICS版本上运行我的应用程序,但如果我在清单中更改min sdkversion n目标sdk版本我的代码无法在ics版本上运行,minsdkversion n targetsdkversion仅使用8。谢谢你的回答。 这是我在清单上的应用程序:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.myapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
                          <activity android:name="com.myapp.news" ></activity>
                          <activity android:name="com.myapp.LazyAdapter"  ></activity>
                          <activity android:name="com.myapp.nasionalAdapter"  ></activity>
                          <activity android:name="com.myapp.SingleMenuItemActivity"></activity>
                          <activity android:name="com.myapp.nasional"  ></activity>
</application>

logcat:

    12-16 13:28:00.023: E/AndroidRuntime(7027): FATAL EXCEPTION: main
    12-16 13:28:00.023: E/AndroidRuntime(7027): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.news}: android.os.NetworkOnMainThreadException
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.os.Handler.dispatchMessage(Handler.java:99)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.os.Looper.loop(Looper.java:137)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.ActivityThread.main(ActivityThread.java:4895)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at java.lang.reflect.Method.invokeNative(Native Method)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at java.lang.reflect.Method.invoke(Method.java:511)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at dalvik.system.NativeStart.main(Native Method)
    12-16 13:28:00.023: E/AndroidRuntime(7027): Caused by: android.os.NetworkOnMainThreadException
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at b1app.function.xmlParser.getXmlFromUrl(xmlParser.java:45)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at com.myapp.news.onCreate(news.java:73)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.Activity.performCreate(Activity.java:5163)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
     12-16 13:28:00.023: E/AndroidRuntime(7027):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
    12-16 13:28:00.023: E/AndroidRuntime(7027):     ... 11 more

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您正在主线程上进行网络操作。这就是你的logcat所说的。

Caused by: android.os.NetworkOnMainThreadException
    12-16 13:28:00.023: E/AndroidRuntime(7027):     at 
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)

在这里阅读更多相关信息。

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

参考这个问题

How to fix android.os.NetworkOnMainThreadException?