skip to Main Content

I have set the button id in xml file but while I tried to find the id of the button it showing an error
xml file

<androidx.appcompat.widget.AppCompatButton
        android:id="@+id/btnrotation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/rorationbtn"
        android:layout_below="@+id/imgbox"
        android:layout_centerInParent="true"
        android:layout_marginTop="50dp">
    </androidx.appcompat.widget.AppCompatButton>

java file

public class rotation extends AppCompatActivity {
    AppCompatButton rotate;
    ImageView imgbox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotation);
        getSupportActionBar().setTitle("Rotation");
        imgbox=findViewById(R.id.imgbox);
        rotate=findViewById(R.id.btnrotation);

    }

error
does not contain a declaration with id ‘btnrotation’

3

Answers


  1. Just rebuild your project and run again

    Login or Signup to reply.
  2. Sometimes it is a bug in android studio, you can try close and reopen Android Studio. If it doesn’t work, you can invalidate caches or clean project and rebuild it.

    Login or Signup to reply.
  3. Just click on Invalidate Caches from top Toolbar (File) , and then click on Invalidate & Restart. Thank You

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search