2

I have been working with elcipse for a couple of weeks now. My code has functioned properly but all of a sudden it has stopped working. I get this error,

main.xml: You must specifiy a valid layout reference. The layout ID @layout/required is not valid.

my XML code

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <!--  select between BIN or auction -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

    <Button
        android:id="@+id/AuctionButton"
        android:layout_marginLeft="82dp"
        android:layout_width="119dp"
        android:layout_height="wrap_content"
        android:onClick="showAuctionOptions"
        android:text="Auction" />


    <Button
        android:id="@+id/BINButton"
        android:layout_marginLeft="-2dp"
        android:layout_width="119dp"
        android:layout_height="wrap_content"
        android:onClick="showAuctionOptions"
        android:text="Buy it now" />

    </LinearLayout>

        <include android:id="@+id/cell1" layout="@layout/required"/>

        <include android:id="@+id/cell2"  layout="@layout/gray_line" />

        <!--**  Show if Buy it now is selected **-->
        <include android:id="@+id/cell3" layout="@layout/buyitnow" />
        <!-- ** End Buy it now display ** -->

        <!--** Show if auction selected ** -->
        <include android:id="@+id/cell4" layout="@layout/auction" />

        <include android:id="@+id/cell5"  layout="@layout/gray_line" />

        <include android:id="@+id/cell6" layout="@layout/addons" />

        <include android:id="@+id/cell7" layout="@layout/calculate" />      

</LinearLayout>

</ScrollView>

the error is with the first include, however if I remove that, I just get an error with the second include. If I remove all of the include, I get a 'could not resolve R' error within my java code.

What I have tried,

  • cleaning the project
  • restarting eclipse
  • rebooting my computer

this is my AndroidManifest XML file,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="toggler.state"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".TogglerActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

none of which have worked.Could anyone help please?

Thanks

rusty009
  • 836
  • 7
  • 16
  • 30

2 Answers2

3

The error is probably caused elsewhere in the layout. Remove the extra two xmlns:android="http://schemas.android.com/apk/res/android"

The xmlns is used to define a namespace. Only the top element can have it in most cases.

Take a look at What does "xmlns" in XML mean? if anyone wants to read about the xmlns explanation.

Also check to make sure your XML files are all lowercase.

Also try to see if you have the correct package specified in your manifest. Taken from https://stackoverflow.com/a/7496766/935779

It is worth checking in AndroidManifest.xml. The attribute package has the correct value.

That is, <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.correct.package.name" ...

After you change that, the R.java will be re-generated.

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


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!--  select between BIN or auction -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >

        <Button
            android:id="@+id/AuctionButton"
            android:layout_marginLeft="82dp"
            android:layout_width="119dp"
            android:layout_height="wrap_content"
            android:onClick="showAuctionOptions"
            android:text="Auction" />


        <Button
            android:id="@+id/BINButton"
            android:layout_marginLeft="-2dp"
            android:layout_width="119dp"
            android:layout_height="wrap_content"
            android:onClick="showAuctionOptions"
            android:text="Buy it now" />

        </LinearLayout>

        <include android:id="@+id/cell1" layout="@layout/required"/>

        <include android:id="@+id/cell2"  layout="@layout/gray_line" />

        <!--**  Show if Buy it now is selected **-->
        <include android:id="@+id/cell3" layout="@layout/buyitnow" />
        <!-- ** End Buy it now display ** -->

        <!--** Show if auction selected ** -->
        <include android:id="@+id/cell4" layout="@layout/auction" />

        <include android:id="@+id/cell5"  layout="@layout/gray_line" />

        <include android:id="@+id/cell6" layout="@layout/addons" />

        <include android:id="@+id/cell7" layout="@layout/calculate" />      

    </LinearLayout>

</ScrollView>
Community
  • 1
  • 1
Kirk
  • 16,182
  • 20
  • 80
  • 112
  • Try cleaning the project again, make sure you have lower case XML file names or forcing the `R` values to regenerate. I've added a few things to the answer. – Kirk Jul 05 '12 at 15:38
  • Thanks again, the project was cleaned after deleting the xmlns and I still have the same problem. the android manifest looks fine to me, I have placed it into the above answer just in case there is an error in it. – rusty009 Jul 05 '12 at 16:30
  • Are there any other XML files in your project with a red x? Maybe others have a duplicate `xmlns` property? – Kirk Jul 05 '12 at 16:37
  • This is what I don't understand, none of the XML files have a red x next to them, only my main activity. When I look at main.xml in graphical view it doesn't show anything, it just states the error. – rusty009 Jul 05 '12 at 16:40
  • XML errors are tough since they are rarely precise. Sadly, I'd suggest looking at each XML and see if you have the duplicate `xmlns` in it to start with. Some errors aren't even reported in Eclipse but cause issues in unexpected places. – Kirk Jul 05 '12 at 16:43
  • Right I found the error. You had already suggested I do this before but I misunderstood, one of my xml files was called 'displayFee.xml' and when I deleted that file the error went. This was because of the uppercase- I thought only the first letter shouldn't be uppercase, not the entire name. I will award you the best answer as you had suggested that in your previous comment. Thank you! – rusty009 Jul 05 '12 at 16:57
0

I had a similar problem and was able to fix it by providing a layout_width and layout_height to the include tag.

Andy Cochrane
  • 2,409
  • 1
  • 18
  • 16