I'm creating an android app with a button, and my xml looks like this:
<Button
android:id="@+id/start"
android:text="Start"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Then I want to get the Button in my main class, but I can't.
Button start;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
start = findViewById(R.id.start);
}
But when I do this, the application won't run because of an error with this line:
start = findViewById(R.id.start);
But I most definitely identified the Button. Can anyone explain why this isn't working?
No comments:
Post a Comment