Android 文档元素和根元素之后的垃圾必须是格式正确的错误
我从一本名为《Android编程大书呆子牧场指南》的书开始学习Android编程,这些就是其中的一个例子。然而,我得到了错误Android 文档元素和根元素之后的垃圾必须是格式正确的错误,android,Android,我从一本名为《Android编程大书呆子牧场指南》的书开始学习Android编程,这些就是其中的一个例子。然而,我得到了错误 错误是:1。分析XML时出错:文档元素后出现垃圾2。文档中根元素后面的标记必须格式正确。3。在布局文件中找到意外文本:“” 我已经检查了这本书的勘误表,但是这段代码没有显示任何内容。 我们将不胜感激 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns
错误是:
- 1。分析XML时出错:文档元素后出现垃圾
- 2。文档中根元素后面的标记必须格式正确。
- 3。在布局文件中找到意外文本:“”
<RelativeLayout 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"
tools:context=".QuizActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
<!-- Error 1 and 2 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!-- Error 3 -->
android:text="@string/true_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />
</LinearLayout>
</LinearLayout>
android:text=“@string/true_按钮”/
<RelativeLayout>
...
</RelativeLayout>
...
及
...
两者都位于文件的根目录下。根目录下只能有一个布局。其余布局应嵌套在根布局元素下
3.在布局文件“”中找到意外文本
对于第三个错误,您可能需要查看答案。基本上,如果在删除错误后执行Build->Clean
,则应该删除该错误。否则,在空白处还有其他字符。然后,您可能希望再次写入xml文件,而不复制粘贴它
<RelativeLayout>
...
</RelativeLayout>
...
及
...
两者都在文件的根目录下。在根目录中只能有一个布局。其余部分应嵌套在根布局元素下
3.在布局文件“”中找到意外文本
对于第三个错误,您可能希望查看答案。基本上,如果您在删除错误后执行
构建->清理
,则应该删除该错误。否则,在空白处有其他字符。您可能希望再次写入xml文件,而不复制粘贴它。对于第三个错误,如果您刚刚有
,那么它也会显示错误吗?是的。我刚刚添加了stackoverflow上的注释以显示错误所在。请查看答案和注释,以及其他问题。对于第三个错误,如果您刚刚遇到
,那么它也会显示错误吗?是的。我刚刚添加了stackoverflow上的注释以显示错误所在。请参阅答案XML不会忽略多余的空白?我只是删除了两个按钮之间的空格,错误也被清除了。有时候,你需要小心一些可能在两行和空行之间的小字符。XML不会忽略多余的空白?我只是删除了两个按钮之间的空格,但是有时你需要注意一些小字符,它们可能在行间,也可能在空行之间。