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