[英]No resource found error in layout xml file android
I get this error in xml file very often.我经常在 xml 文件中收到此错误。 here is the code in xml file这是 xml 文件中的代码
<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 // 然后我检查了 R.java 文件,这个名字的 ID 在那里
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谢谢
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.您应该首先在使用 ID 的地方使用@+id/tRowMain
语法,而不一定是在将它定义为元素 ID 的第一个地方。
Change:改变:
android:layout_above="@id/tRowMain"
to android:layout_above="@+id/tRowMain"
android:layout_above="@id/tRowMain"
到android:layout_above="@+id/tRowMain"
and和
android:id="@+id/tRowMain"
to android:id="@id/tRowMain
android:id="@+id/tRowMain"
到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.换句话说,在决定是否使用@+id
或@id
时,将 id 分配给哪个属性并不重要。 Always use @+id
the first time you mention your ID in the XML.第一次在 XML 中提及您的 ID 时始终使用@+id
。
android:layout_above="@+id/tRowMain"
If it does'nt work delete your R.java file.如果它不起作用,请删除您的 R.java 文件。 It will be re-generated会重新生成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.