1

我是 Java 编程的新手,现在正在严格遵循一个教程。我深入研究了它,直到发生了我无法解决的事情。我搜索了谷歌并一遍又一遍地查看代码,并没有发现任何错误。这是我的代码的屏幕截图....nvm 我不允许发布图片,因为我是新手,所以这里是复制的代码。第一个 X 表示解析 XML 时出错:格式不正确(无效标记),第二个 X 表示 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
4

4 回答 4

1

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 >
于 2012-06-17T05:34:24.687 回答
0

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

`

于 2012-06-17T05:36:39.087 回答
0

您不能允许在打开的标签和标签名称之间留出空格。给出没有空格的线性布局标签

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" >

这是错误的

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
于 2012-06-17T05:37:24.630 回答
0

从标签中删除空格<LinearLayout.use<LinearLayout而不是< LinearLayouas

<?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>
于 2012-06-17T05:37:26.963 回答