Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No resource found error in layout xml file android

I get this error in xml file very often. here is the code in xml file

 <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_centerHorizontal="true"
        android:layout_above="@id/tRowMain"   // in this line i get error resource not found that matches given name
        android:textColor="@color/selectLevel"
        android:id="@+id/tvOnOption"
        android:text="Select Mode"
        />      
    <TableRow android:layout_width="fill_parent" android:id="@+id/tRowMain"
    android:layout_height="wrap_content" android:gravity="center" android:layout_centerVertical="true" android:layout_centerHorizontal="true" >

//then i checked in R.java file and the id for this name is there

public static final class id {
        public static final int ibtn_retry=0x7f060006;
        public static final int rLayoutMain=0x7f060000;
        public static final int tRowMain=0x7f060002;

    }

please help me figure out whats wrong with this...

thanks

like image 897
appdroid Avatar asked Dec 20 '22 23:12

appdroid


2 Answers

You should use the @+id/tRowMain syntax in the first place the ID is used, not necessarily the first place where you define it as the ID of the element.

Change:

android:layout_above="@id/tRowMain" to android:layout_above="@+id/tRowMain"

and

android:id="@+id/tRowMain" to android:id="@id/tRowMain

In other words, when deciding whether or not to use @+id or @id, it doesn't matter which attribute you're assigning the id to. Always use @+id the first time you mention your ID in the XML.

like image 142
Jason LeBrun Avatar answered Jan 08 '23 19:01

Jason LeBrun


android:layout_above="@+id/tRowMain"

If it does'nt work delete your R.java file. It will be re-generated

like image 27
ali Avatar answered Jan 08 '23 17:01

ali