解析XML时出错:格式不正确(无效标记)
问题描述:
我是java编程新手,现在严格遵循一个教程。直到发生了一些我无法修复的事情时,我已经深入了解它。我搜索谷歌,一遍又一遍地查看代码,并没有看到任何错误。这里是我的代码截图.... nvm我不允许发布图片,因为我是新手,所以这里是代码复制。第一个X表示错误解析XML:没有正确形成(无效标记),第二个X表示XML文档结构必须在同一实体内开始和结束。我感谢所有的帮助,谢谢。解析XML时出错:格式不正确(无效标记)
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
< LinearLayout--------1st X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
<LinearLayout>---------2nd X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here and there is a/in between < and LinearLayout
答
xml结构不好......下面是更正后的一个。 不应该有< LinearLayout &之间的空间此标记未正确关闭。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
</LinearLayout >
</LinearLayout >
答
你错过在底部有一个结束标记</LinearLayout>
。在这里工作的一个`
<TextView
android:id="@+id/myMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/answer" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:text="red"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00ff00"
android:gravity="center"
android:text="green"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0000ff"
android:gravity="center"
android:text="blue"
android:textColor="#000000" />
</LinearLayout>
`
答
你不能让给予公开的标签和标签名之间的空间。给线性布局标签没有空间像
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" >
这是错误的
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
答
从<LinearLayout
标签中的空格。使用<LinearLayout
,而不是作为< LinearLayou
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
</LinearLayout>
</LinearLayout>
完成XML代码。其不完整 – Akilan