I'm an android novice. I'm trying to do some practice work but I am getting these two errors that I've tried for hours to fix
error: cannot find symbol variable activity_main
error: cannot find symbol variable tabLayout
Below is my MainActivity.java then after that the activity_main.xml
package com.example.rawtablayoutdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import android.R;
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
}
}
this is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
My screen that shows me the two errors
I'm sure you deep masters of code know the solution for my simple question born from a lack of understanding of Android Studio and making android apps. Please enlighten me.
Try deleting the import statement import android.R
. Most probably it will work, if it doesn't try clearing and rebuilding the project from the Build -> Clean Project, then Build -> Rebuild Project.