【问题标题】:Multiple annotations found at this line: - The markup in the document following the root element must be well- formed在这一行发现多个注释: - 文档中根元素之后的标记必须格式正确
【发布时间】:2014-03-11 02:28:26
【问题描述】:

我是编码新手,非常想学习。
我在 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>

【问题讨论】:

    标签: android xml parsing r.java-file


    【解决方案1】:

    您的问题在这里:

    <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 融合;

    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
    

    在那里定义你的价值观等等,一切都应该得到解决。

    【讨论】:

    • 感谢您的回答。我没有使用 linux。我有 windows。我仍然有这部分的问题:
    • 您的实际问题是什么?
    • 您是否定义了要引用的@String 参数?否则,您问题中的代码是正确的。
    • 我不断收到“在此行找到多个注释:-错误:错误:未找到与给定名称匹配的资源(在 '提示',值为 '@string/edit_message')。”使用这个特定的代码块。
    • 成功了!谢谢!正如你所说,我必须构建资源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多