android - 在此行 : - The markup in the document following the root element must be well- formed 找到多个注释

标签 android xml parsing r.java-file

我是编码新手,非常想学习。
我在 developer.android.com 网站上自学。
不幸的是,我遇到了泥潭,无法通过这段代码。
请帮忙。我做错了什么?
如果你想看这里的练习,地址是:
http://developer.android.com/training/basics/firstapp/building-ui.html#Button

<?xml version="1.0" encoding ="utf-8" ?>
<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" />

    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        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>

最佳答案

您的问题在这里:

<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" />

注意你有

/> 

这将关闭线性布局标签。它应该看起来像这样:

<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" >

without the closing /

注意:

如果您使用的是 Linux,确定您是否正确复制了教程中的代码的一个非常简单的方法是使用 Meld。我将你的代码复制到文件名 1 中,将教程代码复制到文件名 2 中,然后执行“meld 1 2”,结果 UI 准确地显示了你的错误是什么,我什至无需思考

编辑:

首先 - 用于 windows 的 meld;

http://meldmerge.org/

关于您的参数问题:

@String/edit_message

您需要在应用程序的字符串资源中定义该值。以下内容摘自

http://developer.android.com/guide/topics/resources/string-resource.html

FILE LOCATION:
res/values/filename.xml  // in oyur case this will likely be Strings.xml

The filename is arbitrary. The <string> element's name will be used as the resource ID.

COMPILED RESOURCE DATATYPE:
Resource pointer to a String.

RESOURCE REFERENCE:
In Java: R.string.string_name
In XML:@string/string_name

SYNTAX:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string
        name="string_name"  // in your case this will be name="edit_message"
        >text_string</string>
</resources>

如果该文件不存在,您可以在以下位置创建它:

/res/values/strings.xml

在那里定义你的值(value)观等等,一切都应该是固定的。

关于android - 在此行 : - The markup in the document following the root element must be well- formed 找到多个注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21733431/

相关文章:

android - dex格式上还不清楚

java - Android - 检测流结束而不是 MediaPlayer 中的连接错误

java - 资源 android :style/TextAppearance. 未找到 Material

SQL Server,将具有多行html代码的文本解析为表格

xml - 如何使用 Bash 解析 XML 文件中的某些标记并将它们存储在数组中?

android - Android 中的 float 透明窗口

Javascript XML DOM 技巧

php - ajax请求后获取json中的值

xml - 如何使用 XML::Twig 获取带有其他标签的标签内容?

java - Java中大整数的解析