简体   繁体   English

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

[英]The <activity> element must be a direct child of the <application> element

I just wanted to launch my application, but it always fails and gives me this error. 我只是想启动我的应用程序,但它总是失败,并给我这个错误。 Before, it would just install the .apk file, but now it just fails to start at all. 以前,它只是安装.apk文件,但现在根本无法启动。 I just began and was following the Android Developing tutorial. 我刚刚开始并一直在关注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>

您的清单中不能包含嵌套的活动标签,请解决此问题,它应该可以工作。

You don't nest Activities in other Activities . 不要嵌套 Activities中的其他Activities This is how it should look like: 它应该是这样的:

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

Do read the Android docs for the AndroidManifest.xml file 阅读AndroidManifest.xml文件的Android文档

YES - for example: 是-例如:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该 <activity> 元素必须是的直接子元素 <application> 元素错误 - The <activity> element must be a direct child of the <application> element error 这<activity>元素必须是<application>库清单中的元素 - The <activity> element must be a direct child of the <application> element In Library Manifest 这<receiver>元素必须是<application>元素 - The <receiver> element must be a direct child of the <application> element 启动画面活动-元素必须是元素[WrongManifestParent]的直接子元素 - Splash Screen Activity - The element must be a direct child of the element [WrongManifestParent] AndroidManifest.xml-元素必须是的直接子元素 <application> 元素错误 - AndroidManifest.xml - The element must be a direct child of the <application> element error 表现出多个问题,活动元素必须是直接子元素 - manifest multiple problems the activity element must be a direct child Android签名的APK构建错误: <service> 元素必须是的直接子元素 <application> 元件 - Android signed apk build error : The <service> element must be a direct child of the <application> element 该 <uses-permission> 元素必须是直接的孩子 <manifest> 根元素 - The <uses-permission> element must be a direct child of the <manifest> root element 什么是错误:(13)错误:<receiver> 元素必须是<application>元素 [WrongManifestParent] 是什么意思,我该如何解决? - What does Error:(13) Error: The <receiver> element must be a direct child of the <application> element [WrongManifestParent] mean and how do i fix it? 数据绑定不支持包括作为合并元素的直接子元素 - Data binding does not support include as a direct child of a merge element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM