【问题标题】:The markup in the document following the root element must be well-formed?根元素之后的文档中的标记必须格式正确吗?
【发布时间】:2013-07-12 19:26:29
【问题描述】:

我在第 9 行的 activity_main.xml 中收到此错误,我不知道为什么请帮忙。

<FrameLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

<WebView
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</FrameLayout>

【问题讨论】:

  • 这是你activity_main.xml的全部内容吗?

标签: java android eclipse ide


【解决方案1】:

在您的 xml 代码中尝试ctrl + shift + F,它将格式化代码并在清理项目后重试。它将起作用。

【讨论】:

    【解决方案2】:

    如果您在谷歌上搜索过这个错误,那么有很多相同的帖子。 例如:

    Android app, The markup in the document following the root element must be well-formed

    The markup in the document following the root element must be well-formed. What is the cause of this?

    Error : The markup in the document following the root element must be well-formed Please help I am new at android

    等等。 基本上它说你只能有整个 XML 文件的一个根元素。您显示的 xml 片段看起来并不完整。只需确保您只有一个 XML 文件的根元素,其余的都是该根元素的子元素。希望这可以帮助。如果没有,请发布完整的 XML 文件,以便我们更好地提供帮助。

    更新

    在上面显示的代码中,您有两个 FrameLayout 根元素。应该只有一个。因此(根据您的需要)将其更改为如下所示,以便只有一个根元素:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fullscreen_custom_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FF000000">
        <FrameLayout
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <WebView
            android:id="@+id/webView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    
    </FrameLayout>
    

    【讨论】:

    • 非常感谢。我认为另一个答案对我有帮助,但保存后它给出了同样的错误。但这做到了。
    • 很高兴它有帮助。只需根据您的需要管理您的 XML。保持 ind 只有一个根元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多