android – 错误找不到与给定名称匹配的资源(在’src’处,值为’@ drawable / button1′)

前端之家收集整理的这篇文章主要介绍了android – 错误找不到与给定名称匹配的资源(在’src’处,值为’@ drawable / button1′)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我以为这本书的代码不正确.在我家的位置试过,它运作良好.发现我的日食真的被打破了.不得不删除并重新安装eclipse.

这是我在这里的第一篇文章,所以如果我没有遵守一些规则,请告诉我.
我试图搜索并找到一些有相同错误的帖子,但他们处理字符串.
我正在关注Absolute Beginners的Android应用程序(第2版)和第179页,您将button1.xml带入res / drawable.当我进入layout / activity_main.xml并输入时

错误地指出android:src“错误错误:找不到与给定名称匹配的资源(在’src’处,值为’@ drawable / button1′).”

现在有一些令我困惑的事情,我正在使用eclipse,我有4个可绘制的文件夹(drawable-hdpi,drawable-ldpi,drawable-mdpi和drawable-xhdpi),我已经去了每个新的>文件4个可绘制的文件夹,并导入了button1_focused.png,button1_pressed.png和button1_normal.png及其各自的分辨率.我还在每个文件夹中放了button1.xml.

button1.xml如下

我试过android:background而不是android:src,那个错误也出来了.我看到它的错误表明src(或后台)没有文件.只是不知道该放什么.

Java代码
    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.

对于由此造成的任何不便,我深表歉意,并感谢社区的帮助.

原文链接:https://www.f2er.com/android/430786.html

猜你在找的Android相关文章