Error parsing XML: junk after document element java程序员

今天开始接触android的Java编程,出现问题了。

我的代码是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity" >

</LinearLayout>

<EditText android:id="@+id/edit_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />

应该把</LinearLayout>放在最后一行。

原因:

这里Android123提示大家一般合法的XML文件只有一个主根节点,比如

<android123>
    <item1/>
    <item2/>
    <item3/>
</android123>

如果出现了Error parsing XML: junk after document element这样的错误,你的想法可能只要主根有多个节点,比如说

 <android123>
    <item1/>
</android123>
<android123>
    <item2/>
    <item3/>
</android123>


原文地址:https://www.cnblogs.com/java20130725/p/3215471.html