错误未找到与给定名称匹配的资源(在"src"处,值为"@ drawable/button1") [英] Error No resource found that matches the given name (at 'src' with value '@drawable/button1')

查看:124
本文介绍了错误未找到与给定名称匹配的资源(在"src"处,值为"@ drawable/button1")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这本书的代码不正确.在我的家中试过了,效果很好.发现我的日食实际上被打破了.必须删除并重新安装eclipse.

这是我在这里的第一篇文章,因此,如果我不遵守某些规则,请告诉我. 我尝试搜索,发现了一些错误相同的帖子,但它们处理的是字符串. 我关注的是适用于绝对初学者的Android Apps(第2版),在第179页上,您将button1.xml放入res/drawable中.当我进入layout/activity_main.xml并输入

This is my first post here so if I didn't follow some of the rules please let me know. I tried to search and found a few post with the same error but they dealt with strings. I'm following Android Apps for Absolute Beginners (2nd Edition) and on page 179 you bring button1.xml into your res/drawable. When I go in layout/activity_main.xml and input

<ImageButton 
    android:id="@+id/button_one"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/button1"
    android:contentDescription="@string/app_name"/>

错误表明android:src错误:错误:找不到与给定名称匹配的资源(在'src'处值为'@ drawable/button1')."

It errors stating that the android:src "error: Error: No resource found that matches the given name (at 'src' with value '@drawable/button1')."

现在有些事情让我感到困惑,我正在使用eclipse,我有4个可绘制的文件夹(drawable-hdpi,drawable-ldpi,drawable-mdpi和drawable-xhdpi),我去了New> File on 4个可绘制文件夹中的每一个,并分别导入具有各自分辨率的button1_focused.png,button1_pressed.png和button1_normal.png.我还把button1.xml放在每个文件夹中.

Now there's a few things confusing me, I'm using eclipse and I have 4 drawable folders (drawable-hdpi,drawable-ldpi, drawable-mdpi, and drawable-xhdpi), I've went to New>File on each of the 4 drawable folders and imported a button1_focused.png, button1_pressed.png, and button1_normal.png with their respective resolutions. I've also put button1.xml in each of the folders.

button1.xml如下

button1.xml is as follows

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
            android:drawable="@drawable/button1_pressed" />
    <item android:state_focused="true"
            android:drawable="@drawable/button1_focused" />
    <item android:drawable="@drawable/button1_normal" />
</selector>

我尝试了android:background而不是android:src,并且也出错了.我看到它的错误指出,src(或背景)中没有文件.只是不确定要放在哪里.

I tried android:background instead of android:src and that errors out as well. I see that its error'ing out stating that there is no file at src (or background). Just not sure what to put there.

Java代码 包com.example.ui_designs;

Java Code package com.example.ui_designs;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

ImageButton imageButton = new ImageButton(context);
imageButton.setImageResource(R.drawable.button1);

}

链接到屏幕截图: http://s7.postimage.org/3v4tu9ifv/UI_Designs.png

推荐答案

我认为这本书的代码不正确.在我的家中试过了,效果很好.发现我的日食实际上被打破了.必须删除并重新安装eclipse.

对于给您带来的任何不便,我深表歉意,并感谢社区的帮助.

I apologize for any inconvenience I may had caused and appreciate the community for the assistance.

这篇关于错误未找到与给定名称匹配的资源(在"src"处,值为"@ drawable/button1")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆