【问题标题】:The <activity> element must be a direct child of the <application> element with Android Studio Android Manifest XML File [closed]<activity> 元素必须是带有 Android Studio Android Manifest XML 文件的 <application> 元素的直接子元素 [关闭]
【发布时间】:2021-08-14 06:59:32
【问题描述】:

我最近接触了 Android Studio 和 Android Java 开发。我在处理 Android Manifest 文件时出现了这个错误。我的项目文件布局如下...

这里的目标是通过将我的 Java 类声明为一项活动来使其成为主要活动,但我一直在查看 StackOverflow 上的不同论坛和问题,但我无法找到答案。我不知道我是否可以将 Java 类作为应用程序的主要活动。这是 XML 文件...

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我试图声明为活动的活动是您在app 文件夹中看到的名为 MainActivity 的文件。我真的不确定如何正确构建项目以允许该文件成为主要应用程序,同时调整我的 Android Manifest 文件。我也在 MainActivity 类中使​​用 Firebase

【问题讨论】:

  • 因错字而投票关闭:您的 application 元素已直接关闭:&lt;application ... /&gt;。它应该是&lt;application ...&gt;,文件末尾带有&lt;/application&gt;

标签: java android android-studio android-manifest


【解决方案1】:

你已经终止了你不应该拥有的application标签:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" **/**>

应该是

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

正确的清单应该是这样的:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多