Cannot resolve symbol ‘button’ -Android Studio

Here are some things you might have forgotten to do:

  • Name your button (give it an id), I think they’re named button1, button2, … by default
  • Use a capital B when declaring the button object:

Button myButton = new Button("play music");

You should make sure you have Button imported in the activity where you want a button (I think you do)

You can add a button with xml, like so:

<Button
     android:id="@+id/button_id"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/play_music_button" />

Leave a Comment