В этом коде : package com.example.myapp_2.UI.view.activities;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

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

import com.example.myapp_2.CartFragment;
import com.example.myapp_2.R;
import com.example.myapp_2.UI.view.fragments.FirstFragment;
import com.example.myapp_2.UI.view.fragments.SecondFragment;
import com.example.myapp_2.UI.view.fragments.ThirdFragment;
import com.example.myapp_2.ViewModel.ViewModels.NoteViewModel;
import com.example.myapp_2.databinding.ActivityMainBinding;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ActivityMainBinding binding;
    private NoteViewModel noteViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        replaceFragment(new FirstFragment());

        Button button = findViewById(R.id.cart_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                replaceFragment(new CartFragment());
            }
        });

        binding.bottomNavigationView.setOnItemSelectedListener(item -> {
            switch(item.getItemId()){
                case R.id.cart_button:
                    replaceFragment(new CartFragment());
                    break;
                case R.id.home:
                    replaceFragment(new CartFragment());
                    break;
                case R.id.profile:
                    replaceFragment(new SecondFragment());
                    break;
                case R.id.settings:
                    replaceFragment(new ThirdFragment());
                    break;
            }
            return true;
        });

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.nav_container, new FirstFragment())
                .addToBackStack(null)
                .commit();
    }

    @Override
    public void onClick(View view) {//2 способ

    }

    private void replaceFragment(Fragment fragment){
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.nav_container,fragment);

        Bundle bundle = new Bundle();
        bundle.putInt("hello world", 4344);
        fragment.setArguments(bundle);

        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
}(ошибка : E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp_2, PID: 19941
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp_2/com.example.myapp_2.UI.view.activities.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.Button.setOnClickListener(android.view.ViewOnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThreadH.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInitMethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.ViewOnClickListener)’ on a null object reference
at com.example.myapp_2.UI.view.activities.MainActivity.onCreate(MainActivity.java:35)) (cart_button находится в FirstFragment)