Search code examples
javaandroidxmleclipse

Android error: You must specifiy a valid layout reference. The layout ID. in eclipse


I have been working with eclipse 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


Solution

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