Error A resource was not found that matches the specified name (in 'src' with the value '@ drawable / button1')

I thought the book had the wrong code. Tried in my hometown and it worked. It turned out that my eclipse really broke. You have to uninstall and reinstall eclipse.

This is my first post, so if I don’t follow some rules, please let me know. I tried to find and find several messages with the same error, but they touched the lines. I follow Android Apps for Absolute Beginners (2nd Edition), and on page 179 you cast button1.xml to your res / drawable. When I go to layout / activity_main.xml and type

<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"/>

Errors indicating that the error is android: src: Error: no resource was found that matches the specified name (in 'src' with the value '@ drawable / button1').

Now they confuse me a bit, I use eclipse, and I have 4 extendable folders (drawable-hdpi, drawable-ldpi, drawable-mdpi and drawable-xhdpi), I went to New> File on each of the 4 available folders and imported button1_focused. png, button1_pressed.png and button1_normal.png with their respective permissions. I also put button1.xml in each of the folders.

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>

I tried android: background instead of android: src and errors too. I see that his error is that there is no file in src (or in the background). Just not sure what to put in there.

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

+5
7

, . , . , . eclipse.

, .

+2

Project Explorer... button1.xml drawable-hdpi.

alll , , , , drawable, .

+1

Java-?

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

,

1: @/drawable

2: drawable-ldpi.

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

, nasalogo drawable-ldpi

/string.xml

<?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>

0

, , "error: : , ( 'background' '@color/default_bg')."

: "/project_/res/values/colors.xml"

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

- :

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

. ( ) 4 . : src= "@drawable/filename" !

0

It happened to me in AndroidStudio, and it turned out that my file was named .png, but it was jpeg.

0
source

All Articles