【问题标题】:AndroidManifest.xml The markup in the document following the root element must be well formedAndroidManifest.xml 文档中根元素后面的标记必须格式正确
【发布时间】:2012-07-26 11:33:34
【问题描述】:

我已经让 Eclipse 生成一个 Basic android Hello World 应用程序,但它有 2 个错误:首先,在我的 AndroidManifest.xml 中这两行:
我得到根元素后面的文档中的标记必须格式正确,而且我的 R.java 也不会生成,无论我清理我的项目多少次。有答案吗?

清单在这里:http://jsfiddle.net/NHDU6/

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jfkingsley.maclogin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


<!--
     Declare the contents of this Android application.  The namespace
     attribute brings in the Android platform namespace, and the package
     supplies a unique name for the application.  When writing your
     own application, the package name must be changed from "com.example.*"
     to come from a domain that you own or have control over.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jfkingsley.maclogin" >

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

    <application
        android:icon="@drawable/ic_launcher_home"
        android:label="@string/home_title" >
        <activity
            android:name="Home"
            android:launchMode="singleInstance"
            android:stateNotNeeded="true"
            android:theme="@style/Theme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="Wallpaper"
            android:icon="@drawable/bg_android_icon"
            android:label="Wallpaper" >
            <intent-filter>
                <action android:name="android.intent.action.SET_WALLPAPER" />

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

</manifest>

谢谢,乔纳森

【问题讨论】:

  • 您是否删除了一个项目,然后创建了另一个同名项目?
  • 不,问题是我有多个应用标签

标签: android xml


【解决方案1】:

这是你的清单,

您不应指定多个Manifest 并且不应指定多个&lt;application&gt; 标签。

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

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

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="h" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="Home"
            android:launchMode="singleInstance"
            android:stateNotNeeded="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="Wallpaper"
            android:icon="@drawable/ic_launcher"
            android:label="Wallpaper" >
            <intent-filter>
                <action android:name="android.intent.action.SET_WALLPAPER" />

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

</manifest>

【讨论】:

    【解决方案2】:

    可能是你遗漏了什么,但有时做一个简单的重新格式化代码:CTRL+SHIFT+F,可以解决问题。

    【讨论】:

      【解决方案3】:

      我查看了您的清单文件。该错误是因为您有 2 个 &lt;manifest /&gt; 标记声明。

      开头是:

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jfkingsley.maclogin"
          android:versionCode="1"
          android:versionName="1.0" >
      

      然后一些 cmets 紧随其后,另一个声明开始:

      <!--
           Declare the contents of this Android application.  The namespace
           attribute brings in the Android platform namespace, and the package
           supplies a unique name for the application.  When writing your
           own application, the package name must be changed from "com.example.*"
           to come from a domain that you own or have control over.
      -->
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jfkingsley.maclogin" >
      
          <uses-permission android:name="android.permission.CALL_PHONE" />
      

      您要么忘记评论清单标签之一,混淆了某些东西,要么遵循了错误的教程。 AndroidManifest 文件应该只有一个&lt;manifest /&gt; 标签

      【讨论】:

        【解决方案4】:

        自动生成的 AndroidManifest.xml 文件本身就有问题。里面有两个manifest标签和两个uses-sdk标签。那就是问题所在。执行以下操作: 1-删除第一个清单标签的结束标签,即: &lt;/manifest&gt; 2- 删除第二个清单标签的定义标签,即:

        <manifest 
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="net.learn2develop.fragments"
        android:versionCode="1"
        android:versionName="1.0" >
        

        3-如果有两个uses-sdk标签,同样删除第二个uses-sdk标签。

        【讨论】:

          【解决方案5】:

          我在我的应用中添加了一个新活动,之后它给出了这个错误。清单完全从 android-studio 中消失了。 我不得不使用文本编辑器编辑清单。似乎当我添加一个新活动时,Android Studio 创建了一个新标签,然后在清单文件中添加了新的活动标签,而不是仅仅在清单中添加带有新活动的标签。 更新清单后,项目运行良好。

          【讨论】:

            【解决方案6】:
            <?xml version="1.0" encoding="utf-8"?>
            

            <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"
                    android:label="@string/title_activity_main"
                    android:theme="@style/AppTheme.NoActionBar"/>
                <activity
                    android:name=".SignUp"
                    android:label="@string/title_activity_sign_up"
                    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>
            

            【讨论】:

              【解决方案7】:

              /> 不应该在文件末尾我有同样的问题,错误意味着 xml 文件的格式不正确,您应该尝试删除 > 前面的 / 或简单地重新格式化

              【讨论】:

              • 问题中文件末尾没有/&gt;。你在说什么?
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多