[Solved] Compiler does not recognize button


The Button and View classes need to be imported; e.g.

import android.widget.Button;
import android.view.View;

Your class is in the default package, so all classes that it uses (apart from those in the java.lang package) need to be imported.

The reference to button_id is probably a mistake.

Button mButton = (Button) findViewById(R.id.button);
final Button button = findViewById(R.id.button_id);  // Delete this line

Alternatively, maybe you need to declare another button in your “activity_main.xml” file whose id is android:id="@+id/button_id"

1

solved Compiler does not recognize button