0

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>
Saggy
  • 624
  • 8
  • 23

1 Answers1

5

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 -->
codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • After Cleaning now R.java file gone and its showing error where ever reference or R used. – Saggy Jun 28 '13 at 18:36
  • You probably have an error in one of your xml files. Correct any errors, including `manifest.xml`, and clean again – codeMagic Jun 28 '13 at 18:38
  • I am not finding an error. I will paste the code here if you can make out please tell me. Its just I am practicing for linking of activity through intent. – Saggy Jun 28 '13 at 18:46
  • Ok, it wouldn't be in your Java code, it would be in your xml – codeMagic Jun 28 '13 at 18:47
  • Its activity_link.xml – Saggy Jun 28 '13 at 18:49
  • second activity named activity_called.xml – Saggy Jun 28 '13 at 18:50
  • the manifest.xml is – Saggy Jun 28 '13 at 18:52
  • Its hard to read in comments but looks ok. You would see red error marks. Eclipse has a "Problems" tab. You can look there and see if it shows anything. If it does, let me know what if you can't figure it out. Otherwise, [See This Post](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) and try restarting Eclipse – codeMagic Jun 28 '13 at 18:53
  • All this is okay. No errors show in Problems View tab. Re started eclipse. Error remains the same. R.Java missing and that the only error indicated in Problems View Tab. – Saggy Jun 28 '13 at 19:18
  • Do you have the `import android.R` in your Java file? – codeMagic Jun 28 '13 at 19:19
  • No. I have used it but making no difference. – Saggy Jun 28 '13 at 19:27
  • Ok, good, you don't want that. You should have something like `import com.your.project.R;` – codeMagic Jun 28 '13 at 19:28
  • Do you have Java compiler set to 1.6? "Project->Properties->JavaCompiler" – codeMagic Jun 28 '13 at 19:30
  • You mean as my package name is com.example.actitvitieslinking So, I have to use com.example.actitvitieslinking.R; – Saggy Jun 28 '13 at 19:31
  • Yes. It should add it for you when you delete R.java from the `gen` folderd – codeMagic Jun 28 '13 at 19:31
  • Yes I did it in the beginning itself. It's set to 1.6. – Saggy Jun 28 '13 at 19:32
  • I'm sorry, I really don't know what else I can tell you without having your complete project in front of me. Maybe post a new question and be sure to list all of the things you've tried including the link to the SO answer I gave you. Maybe someone else will think of something I'm missing right now – codeMagic Jun 28 '13 at 19:34
  • I'm sorry, pal, I'm out of ideas at the moment. I've answered a lot of questions and made a lot of comments already today. Maybe my brain is stuck :( – codeMagic Jun 28 '13 at 19:35
  • The only other thing I can think of is if you need to update your SDK...try that – codeMagic Jun 28 '13 at 19:37
  • Yesterday only I have updated it to 22.0.1. So, at the moment at won't work as rest of my projects are just running smoothly. Anyway, – Saggy Jun 28 '13 at 19:38