Error No resource found that matches the given name (at 'src' with value '@drawable/button1')

纵然是瞬间 提交于 2019-12-05 12:57:04

I thought the book had incorrect code. Tried at my home location and it worked. Found out that my eclipse was actually broken. Had to remove and re install eclipse.

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

According to the screenshot of your Project Explorer... you do not have the button1.xml in your drawable-hdpi folder.

If you wish to use alll of the same image sizes, density does not matter, you can make a new folder called nothing other then just drawable which will handle all screen densities.

I had a similar problem because

1: I did not add the proper image's name after @/drawable

2: I also did not add the image in the drawable-ldpi folder.

<ImageView
    android:id="@+id/imageDisplay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/nasalogo">
</ImageView>

In my case I needed to add the image called nasalogo in my drawable-ldpi folder

Also this is what my values/string.xml looks like

<?xml version="1.0" encoding="utf-8"?>

PCWorldRssReaderActivity

<string name="text_image_title">Decorating the Sky</string>

<string name="text_image_date">Mon, 19 Aug 2013 00:00:00 EST </string>
<string name="text_image">nasalogo</string>

<string name="text_image_description"> This is mosaic image</string>

Later

Could you try doing this in your java code ?

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

I was hit by this while I was reverse engineering a project, "error: Error: No resource found that matches the given name (at 'background' with value '@color/default_bg')."

Resolution: Added this following attribute to "/project_/res/values/colors.xml"

<color name="default_bg">#aa000000</color>

Finally it looked liked something this:

<resources>
  <color name="black_overlay">#66000000</color>
   <color name="default_bg">#aa000000</color>
</resources>

There is another solution to it. Copy all the image folders (with the same name) onto all the 4 drawable folders. and execute android:src="@drawable/filename" It worked for me then!

I had this happen in AndroidStudio and it turned out that my file was named .png but was a jpeg.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!