`

解决 No resource found that matches the given name (at 'layout_above' with value '@id/button3').

 
阅读更多

今天继续学习郭少的<<第一行代码>>,读到3.3.2相对布局这一章(P102页),根据书上的实例,运行以后在控制台显示了,

Information:Gradle tasks [:app:assembleDebug]
C:\Users\Administrator\AndroidStudioProjects\UILayoutTest\app\src\main\res\layout\activity_main.xml
Error:(10, 31) No resource found that matches the given name (at 'layout_above' with value '@id/button3').
Error:(11, 34) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/button3').
Error:(17, 31) No resource found that matches the given name (at 'layout_above' with value '@id/button3').
Error:(18, 35) No resource found that matches the given name (at 'layout_toRightOf' with value '@id/button3').

 

好你是说没有找到与‘@id/button3‘匹配的名字的资源,怎么回事呢,仔细看了一下activity_main.xml,发现了问题

 

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_toLeftOf="@id/button3"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_toRightOf="@id/button3"
android:text="Button 2" />
<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="Button 3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"
android:text="Button 4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button3"
android:layout_toRightOf="@id/button3"
android:text="Button 5" />

 

最后读到第103页,上面清楚的写到。注意,当一个控件去引用另一个控件的id时,该控件一定要定义在引用控件的后面,不然会出现找不到id的情况将button3写到中间了,将button3的位置放到button1上面就行了,期待大家不要犯同样的错误!

 

分享到:
评论

相关推荐

    apktool_AndResGuard:修复apktool打包出现No resource found...

    No resource found that matches the given name..... ....... 使用apktool-2.0.3也可以回编译,但是比如微信回编译后会增加到110M左右,很不友好。 而使用apktool-2.3.2和原包大小一样,65M左右。 基于apktool

    lichee_20170502_1607_全志R16的linux系统编译需要改动的文件_使用parrotv1.1的内核_没有外层目录.7z

    rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh config Welcome to mkscript setup progress All available chips: 0. sun8iw5p1 Choice: 0 All available platforms: 0. android 1. ...

    RunAsTI-master.zip

    The curious ones might notice that RunFromToken is attached as a resource. Have added the original source of RunFromToken as the exe's must be present in current directory when building RunAsTi. ...

    android 百度地图 定位示例

    final Button btn_location = (Button) findViewById(R.id.btn_location); btn_location.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-...

    lunch_cb5801_r58_20160907.7z

    ./configs/media_profiles.xml: not perform any checks at all. 不用修改 ./vendorsetup.sh:add_lunch_combo octopus_perf-eng ./vendorsetup.sh:add_lunch_combo octopus_perf-user 直接用cb5801搜索替换perf...

    lunch_r58_20160906.7z

    ./configs/media_profiles.xml: not perform any checks at all. 不用修改 ./vendorsetup.sh:add_lunch_combo octopus_perf-eng ./vendorsetup.sh:add_lunch_combo octopus_perf-user 直接用cb5801搜索替换perf...

    signal PYQT5

    onNewSelection@resource://devtools/client/inspector/inspector.js:1324:5 emit@resource://devtools/shared/event-emitter.js:178:15 emit@resource://devtools/shared/event-emitter.js:255:5 setNodeFront@...

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh config Welcome to mkscript setup progress All available chips: 0. sun8iw5p1 Choice: 0 All available platforms: 0. android 1. ...

    Xamarin开发Android不显示标题栏,隐藏title

    为了隐藏标题栏,我们需要创建一个继承自Android原生主题(如`Theme.AppCompat.Light.NoActionBar`或`Theme.Material3.DayNight.NoActionBar`,具体取决于你的Android支持库版本)的新主题。在`styles.xml`文件中...

    Resource ‘taggers/averaged_perceptron_tagger/averaged_perceptron _tagger.pickle’ not found.

    错误如下: LookupError: ********************************************************************** Resource 'taggers/averaged_... obtain the resource: &gt;&gt;&gt; nltk.download() Searched in: - 'C:\\Users\\Dr

    微信小程序npm引入vant-weapp的踩坑记录

    本文详细记录了在微信小程序项目中引入vant-weapp(一种基于Vue的轻量、可靠的移动端UI框架)时所遇到的一些问题及其解决方法。以下将根据文章内容,详细阐述微信小程序中使用npm引入依赖的流程、遇到的问题以及解决...

    SVN各种错误提示产生原因及处理方法大全

    5. The version of your subversion (client) is below 1.5.0, upgrade to 1.5.0 or above. 该错误提示的原因是客户端的软件版本低于 1.5.0。解决方法是升级本地的 Subversion 客户端软件到 1.5.0 或以上版本,以...

    andoid的man

    - error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/icon'). - Should explicitly set android:allowBackup to true or false (it's true by default, and ...

    Rhino5_Python_Primer.pdf

    The RhinoPython community is very active and offers a wonderful resource for posting questions/answers and fi nding help on just about anything!: http://python.rhino3d.com/forums/ General References ...

    S60_Platform_Power_and_Resource_Management_Example_v2_1_en.zip

    how to implement some of the power and resource management principles that have been discussed in the document S60 Platform: Effective Power and Resource Management (available at ...

    rsh软件(LoadRunner监控Linux)

    Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility for this verification). Detailed error: RPC: Failed to create RPC client.  RPC-TCP: Failed to ...

    mysql安装配置设置

    mysql安装配置设置; error: can't create transaction lock on /var/lib/rpm/__db.000 解决方法: rm -f /var/lib/rpm/__db.* rpm --rebuilddb yum clean all

    php.ini-development

    you may only use these constants *after* the line that loads the extension. ;;;;;;;;;;;;;;;;;;; ; About this file ; ;;;;;;;;;;;;;;;;;;; ; PHP comes packaged with two INI files. One that is ...

    Xamarin Android Navigation Drawer Layout简单例子

    drawerLayout = FindViewById(Resource.Id.drawer_layout); navigationView = FindViewById(Resource.Id.nav_view); // 设置HomeAsUpIndicator并监听点击事件 ActionBarDrawerToggle toggle = new ...

    ImagesWidget.rar

    android:label="@string/app_name" android:debuggable="true"&gt; android:name=".ImagesWidgetConfiguration" android:label="@string/app_name"&gt; android:name="android.intent.action.MAIN" /&gt; ...

Global site tag (gtag.js) - Google Analytics