Reputation: 624
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>
Upvotes: 0
Views: 4487
Reputation: 44571
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 -->
Upvotes: 5