Very frustrating problem I have here. I have this code:
Button b = findViewById(android.R.id.button1);
And I’m getting this error on it:
Type mismatch: cannot convert form View to Button
But button1 is a button!! In my XML layout document the button has been declared like this:
<Button
android:id = "@+id/button1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Next Activity"
/>
And in my R.java:
public static final class id {
public static final int button1=0x7f050000;
}
Why I get and error saying that my button is a view when it actually is indeed a button… is a mystery.
You need to cast the view to Button:
More details at http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
In addition, as answered by others, the id is wrong.