简体   繁体   English

不确定在创建新的 class 时如何正确编辑我的 AndroidManifest.xml

[英]Unsure how to correctly edit my AndroidManifest.xml when creating a new class

I'm currently building my first Android app using Java.我目前正在使用 Java 构建我的第一个 Android 应用程序。 I am trying to add a class to my app called Pop.java that displays a pop up message.我正在尝试将 class 添加到我的名为 Pop.java 的应用程序中,该应用程序显示弹出消息。 However, when compiling its telling me my configuration is incorrect and I am getting an "AndroidManifest.xml does exist of has incorrect root tag" error.但是,在编译时告诉我我的配置不正确,并且我收到“AndroidManifest.xml 确实存在根标签不正确”错误。 When looking it up it seems like I need to update my.xml file to add this.Pop class.查找时似乎我需要更新 my.xml 文件以添加 this.Pop class。 Here is what I'm trying right now thats still giving me errors:这是我现在正在尝试的,但仍然给我错误:

<?xml version="1.0" encoding="utf-8"?>
<activity xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.hungry15">

    <activity
        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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity> android:name=".Pop" ></activity>
    </application>
</manifest>

The only part I edited of this.xml file was我编辑的 this.xml 文件的唯一部分是

</activity> android:name=".Pop" ></activity>

Any help on where I'm going wrong would be greatly appreciated!!任何关于我哪里出错的帮助将不胜感激!

Your first two Tags are wrong!你的前两个标签是错误的!

Open manifest and application .打开清单应用程序 For each tag you open you need to close.对于您打开的每个标签,您都需要关闭。 Also New Activities live inside application tag.新活动也存在于应用程序标签内。

Also you are opening a new tag for activity wrongly此外,您错误地为活动打开了一个新标签

</activity> android:name=".Pop" ></activity>

Should be应该

<activity android:name=".Pop" ></activity>

The Manifest fixed bellow清单固定如下

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

    <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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity android:name=".Pop" ></activity>
    </application>
</manifest>

Just do some correction to the AndroidManifest.xml:只需对 AndroidManifest.xml 进行一些更正:

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

  <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=".Pop"/> <!--here is your activity, you wanna add!-->
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM