元素类型"按钮"必须后跟属性规范,">"或QUOT; />"后跟、按钮、属性、元素

2023-09-04 03:50:27 作者:’我是东施。

我创造了我的XML按钮,在此创建参数

 <按钮机器人:ID =@ + ID / BTN2
  --->机器人:layout_width =WRAP_CONTENT< ----
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=@字符串/ PNR
/>
 

我正在和行错误标明说:

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

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

我已经检查先前的职位,但他们表示,标记未封闭,并没有为我工作。

请建议我,该怎么办?这里是全code:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

<按钮机器人:ID =@ + ID / BTN2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=@字符串/ PNR
    />

< / LinearLayout中>
 
jQuery事件 动画

解决方案

尝试清洁您的项目

  

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

有时候Eclipse不拿起更改您的XML。当你愚蠢的错误,像这样总是尝试清洁第一。有时候,你会得到 ClassCastException异常运行时的Java code更改的东西在XML像

之后   

不能施放按钮的EditText

或类似的东西,将没有任何意义。这也是一个很好的时间来清理你的项目。

我也建议摆脱空白的元素中,因为我有麻烦了,以及(特别是在旧版本的Eclipse),再加上我认为它看起来更干净。所以,我会改变你的<按钮...

 <按钮机器人:ID =@ + ID / BTN2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/ PNR/> <! - 刚搬到你的结束标签,以这条线 - >
 

I am creating a button in my XML and here is the creation parameters

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

I am getting and error in the line indicated saying :

" Element type "Button" must be followed by either attribute specifications, ">" or "/>" "

Not only in button id I try to create TextView or so then also same error comes and at same place.

I have checked earlier posts but they said that the tags were not closed and did not worked for me.

Please suggest me, what to do? Here is the full code :

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

解决方案

Try cleaning your project

Project --> Clean... then choose your project

Sometimes Eclipse doesn't pick up changes to your xml. When you get goofy errors like this always try cleaning first. Sometimes you will get ClassCastException in Java code when running right after changing something in xml like

cannot cast Button to EditText

or something similar that won't make sense. This is also a good time to clean your project.

I would also recommend getting rid of whitespace within elements because I have had trouble with that as well (especially on older versions of Eclipse) plus I think it looks cleaner. So I would change your <Button... to

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