<activity>元素必须是<application>元素</application> </activity>的直接子元素

时间:2013-05-04 07:05:31

标签: android xml eclipse android-activity metadata

我只是想启动我的应用程序,但它总是失败并给我这个错误。之前,它只会安装.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>

3 个答案:

答案 0 :(得分:3)

你的Manifest中不能有嵌套的活动标签,解决这个问题,它应该有效。

答案 1 :(得分:1)

您没有嵌套 Activities在其他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 file

的Android文档

答案 2 :(得分:0)

是 - 例如:

<?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>