簡體   English   中英

Android 應用程序,根元素后面的文檔中的標記必須格式正確

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

我已經開始從下面的鏈接模塊 6.1 項目http://www.vogella.de/articles/Android/article.html開始研究一些 android 教程演示

我在 eclipse 中收到以下菜單標簽的錯誤通知。xml:

The markup in the document following the root element must be well-formed.

menu.xml(路徑:/res/menu)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button android:id="@+id/Button01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Show Preferences"></Button>
    <Button android:id="@+id/Button02" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Change Preferences"></Button>
</LinearLayout>
   <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:title="Prefernces" android:id="@+id/Prefernces"></item>
</menu>

在控制台中出現以下錯誤:

[2011-08-17 14:47:00 - Preferences] D:\AndroidWorkSpace\Preferences\res\menu\menu.xml:10: error: Error parsing XML: junk after document element
[2011-08-17 14:47:02 - Preferences] W/ResourceType( 3524): Bad XML block: no root element node found
[2011-08-17 14:47:02 - Preferences] D:\AndroidWorkSpace\Preferences\res\menu\menu.xml:10: error: Error parsing XML: junk after document element

我錯過了什么嗎?

最后一個menu標簽來自哪里? 你應該只有一個根(即第一級)標簽,這里是LinearLayout

格式良好的 XML 有一個根元素(這不包括標題),所以它基本上抱怨的是你的根中有兩個元素:LinearLayout 和 Menu。 將它們包裝在另一個布局元素中或將菜單移動到 LinearLayout 中,應該沒問題。

我同意這個診斷,但是錯誤信息非常需要改寫:“根元素之后的文檔中的標記必須格式正確。” 它表明可以有一些“根元素之后的文檔中的標記”,並且它應該是格式正確的。 實際上,根元素后面根本不能跟任何東西。 因此,任何文本都無法形成良好的格式。

<menu>需要將 go 放入自己的文件中。

XML 總是有一對封閉標簽(例如<foo> </foo>其中所有其他元素 go 介於兩者之間。在您的示例中不是這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM