简体   繁体   English

在布局 xml 文件 android 中找不到资源错误

[英]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.

相关问题 布局xml中的资源,但编译器错误,显示“未找到” - Resource in layout xml but compiler error with “not found” 如何修复Android布局中找不到资源的错误 - how to fix resource not found error in android layout Android:从xml资源到布局文件的整数 - Android: integer from xml resource into a layout file [Android] [XML]错误:(19,31)找不到与给定名称匹配的资源。(layout_above) - [Android][XML]Error:(19, 31) No resource found that matches the given name.(layout_above) Android XML资源文件错误 - Android XML resource file error Android Studio 中的动画 xml 文件中的“布局文件中发现意外文本”错误? - “Unexpected text found in layout file” error in anim xml file in Android Studio? 错误:在包“ android”中找不到属性“ layout_alignStart”的资源标识符 - error: No resource identifier found for attribute 'layout_alignStart' in package 'android' 错误:在包“ android”中找不到属性“ layout_toLeftof”的资源标识符 - error: No resource identifier found for attribute 'layout_toLeftof' in package 'android' Android布局错误:在包中找不到属性“ lineWidth”的资源标识符 - Android layout error: no resource identifier found for attribute 'lineWidth' in package 错误:在包“ android”中找不到属性“ layout_width”的资源标识符:( - error : no resource identifier found for attribute 'layout_width' in package 'android' :(
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM