【问题标题】:Element type "Button" must be followed by either attribute specifications, ">" or "/>"元素类型“按钮”必须后跟属性规范,“>”或“/>”
【发布时间】:2013-06-28 18:24:29
【问题描述】:

我正在我的 XML 中创建一个按钮,这里是创建参数

<Button android:id="@+id/btn2"
  --->  android:layout_width="wrap_content"  <----
    android:layout_height="wrap_content"
    android:text="@string/PNR"
/>

我得到并且错误指示在行中说:

" 元素类型 "Button" 必须后跟属性规范,">" 或 "/>""

不仅在按钮 id 中,我尝试创建 TextView 左右,然后同样的错误也出现在同一个地方。

我检查过之前的帖子,但他们说标签没有关闭,对我不起作用。

请给我建议,该怎么做?这是完整的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<Button android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/PNR"
    />

</LinearLayout>

【问题讨论】:

    标签: android xml eclipse


    【解决方案1】:

    尝试清理您的项目

    项目 --> 清理...然后选择您的项目

    有时 Eclipse 不会获取对您的 xml 的更改。当您遇到此类愚蠢的错误时,请务必先尝试清洁。有时,在更改 xml 中的某些内容(例如

    无法将 Button 转换为 EditText

    或类似的东西,没有意义。这也是清理项目的好时机。

    我还建议去掉元素中的空格,因为我也遇到过这个问题(尤其是在旧版本的 Eclipse 上),而且我认为它看起来更干净。所以我会把你的&lt;Button...改成

    <Button android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/PNR"/>  <!-- just moved your end tag to this line -->
    

    【讨论】:

    • 现在清理后 R.java 文件消失了,并且在使用过引用或 R 的地方显示错误。
    • 您的某个 xml 文件中可能有错误。更正所有错误,包括manifest.xml,然后再次清理
    • 我没有发现错误。我会把代码贴在这里,如果你能看出来请告诉我。它只是我正在练习通过意图链接活动。
    • 好的,它不会在你的 Java 代码中,它会在你的 xml 中
    • 它的activity_link.xml
    猜你喜欢
    • 2017-03-12
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 2014-01-12
    • 1970-01-01
    相关资源
    最近更新 更多