Android Studio - 'activity'元素必须是'application'元素的直接子元素

时间:2018-02-14 11:51:06

标签: android manifest

我为我的程序编写了一个语言函数,需要在清单中声明一个模块,我已经这样做了:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.nakoncisveta.eyetracksample.eyedetect"
android:versionCode="301"
android:versionName="3.01">

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

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true" />

<uses-permission android:name="android.permission.CAMERA" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front.autofocus"
    android:required="false" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:name="com.example.donteh.cvimagedetection.LanguageOverride"/>
    <activity
        android:name="com.example.donteh.cvimagedetection.UiActivity"
        android:theme="@style/AppTheme"
        android:label="@string/app_name"
        android:icon="@drawable/eyes">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.donteh.cvimagedetection.MainActivity"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges = "keyboardHidden|orientation" />
</application>

编译器在应用程序标记处给出了一个错误,说“'activity'元素必须是'application'元素的直接子元素。我用Google搜索了它,常见的问题似乎是某些'活动'元素超出'application'元素。但是,我确保所有'活动'元素都在'application'元素下。

奇怪的是,在应用程序标记中添加一个结束括号似乎可以解决问题。但是,这意味着我无法声明哪个模块会出现问题。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.nakoncisveta.eyetracksample.eyedetect"
android:versionCode="301"
android:versionName="3.01">

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

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true" />

<uses-permission android:name="android.permission.CAMERA" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front.autofocus"
    android:required="false" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application>
    android:name="com.example.donteh.cvimagedetection.LanguageOverride"/>
    <activity
        android:name="com.example.donteh.cvimagedetection.UiActivity"
        android:theme="@style/AppTheme"
        android:label="@string/app_name"
        android:icon="@drawable/eyes">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.donteh.cvimagedetection.MainActivity"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges = "keyboardHidden|orientation" />
</application>

1 个答案:

答案 0 :(得分:1)

见这一行:

<application
android:name="com.example.donteh.cvimagedetection.LanguageOverride"/>

标签末尾的/>表示它是自动关闭的。在这种情况下,您不想这样做,因为您想要包含<activity>等子元素。要解决此错误,请删除标记末尾的/,如下所示:

<application
android:name="com.example.donteh.cvimagedetection.LanguageOverride">