gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:06:33 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com