I have been trying to go from an empty activity to a tab layout but the app keeps crashing once button is clicked. Without the empty activity the code worked fine.

Main activity (empty) 

```
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void statsButton(View view){
    Intent intent = new Intent(this, stats.class);
    startActivity(intent);
}

}

```

Stats.java (where I want tabbed view to start)

```
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabItem;
import com.google.android.material.tabs.TabLayout;

public class stats extends AppCompatActivity {

private TabLayout tabLayout;
private ViewPager viewPager;
private TabItem tab1,tab2,tab3;
public PageAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tabLayout = (TabLayout) findViewById(R.id.tablayout);
    tab1 = (TabItem) findViewById(R.id.Tab1);
    tab2 = (TabItem) findViewById(R.id.Tab2);
    tab3 = (TabItem) findViewById(R.id.Tab3);
    viewPager = findViewById(R.id.viewpager);

    pagerAdapter = new PageAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(pagerAdapter);

    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
            if (tab.getPosition() == 0 ) {
                pagerAdapter.notifyDataSetChanged();
            }
            else if (tab.getPosition() == 1){
                pagerAdapter.notifyDataSetChanged();
            }
            else if (tab.getPosition() == 2){
                pagerAdapter.notifyDataSetChanged();
            }
        }
        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

}
}

```

for some reason these errors are given in crash log once the stats button is clicked and I don't know what the problem is

[crashlog](https://i.stack.imgur.com/Q4u3S.png)

my manifest looks like this

```
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emptytab">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

```