1

我只是想启动我的应用程序,但它总是失败并给我这个错误。以前,它只会安装 .apk 文件,但现在它根本无法启动。我刚刚开始并正在关注 Android 开发教程。

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.myfirstapp"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.myfirstapp.MainActivity"
                android:label="@string/app_name" >
                <activity
                    android:name="com.example.myfirstapp.DisplayMessageActivity"
                    android:label="@string/title_activity_display_message"
                    android:parentActivityName="com.example.myfirstapp.MainActivity" >
                    <meta-data
                        android:name="android.support.PARENT_ACTIVITY"
                        android:value="com.example.myfirstapp.MainActivity" >
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />
                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </meta-data>
                </activity>
            </activity>
        </application>

    </manifest>
4

3 回答 3

4

您的清单中不能有嵌套的活动标签,解决这个问题,它应该可以工作。

于 2013-05-04T07:07:08.663 回答
2

是 - 例如:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example" android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="3" />

  <uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
  <uses-permission android:name="android.permission.VIBRATE"></uses-permission>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />

  <uses-feature android:name="android.hardware.camera" /> 

  <application 
      android:icon="@drawable/icon" android:label="@string/app_name">

    <!-- Boot window -->
    <activity 
        android:name=".ServicesDemo" android:label="@string/app_name">        
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />           
        <category android:name="android.intent.category.HOME" />     
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>

    </activity>

    <!-- Second window -->
    <activity android:name=".MainActivity" android:label="@string/app_name" 
        android:parentActivityName=".ServicesDemo" />       
    <!-- Second window -->
    <activity android:name=".MyWall" android:label="@string/app_name" 
        android:parentActivityName=".ServicesDemo" />    
    <!-- Second window -->
    <activity android:name=".MyRotations" android:label="@string/app_name" 
        android:parentActivityName=".ServicesDemo" />
    <!-- Second window -->
    <activity android:name=".MySetting" android:label="@string/app_name" 
        android:parentActivityName=".ServicesDemo" />

    <receiver 
        android:enabled="true"
        android:name=".IntentReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
        >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />            
            <action android:name="android.intent.action.HEADSET_PLUG" />
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />            
            <category android:name="android.intent.category.DEFAULT" />            
        </intent-filter>
    </receiver>  

    <service android:enabled="true" android:name=".MyService" />
    <service android:enabled="true" android:name=".MyNewpic" />

  </application>

</manifest> 
于 2013-07-25T09:52:21.167 回答
1

你不会嵌套 Activities在 other 中Activities。它应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="com.example.myfirstapp.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.example.myfirstapp.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.myfirstapp.MainActivity" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </meta-data>
        </activity>
    </application>

</manifest>

请阅读AndroidManifest.xml 文件的 Android 文档

于 2013-05-04T07:06:51.390 回答