Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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

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 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 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 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);

}

Link to the screenshot: http://s7.postimage.org/3v4tu9ifv/UI_Designs.png

like image 659
ZeroAccess Avatar asked Oct 05 '22 04:10

ZeroAccess


1 Answers

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.

like image 51
ZeroAccess Avatar answered Oct 10 '22 04:10

ZeroAccess