title: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference , in fragment
body: <p>When i want to run some function on the fragment i got this error,</p>
  
  <p>My error</p>
  
  <blockquote>
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
            at androidx.fragment.app.FragmentTransaction.doAddOp(FragmentTransaction.java:161)
            at androidx.fragment.app.BackStackRecord.doAddOp(BackStackRecord.java:179)
            at androidx.fragment.app.FragmentTransaction.replace(FragmentTransaction.java:225)
            at androidx.fragment.app.FragmentTransaction.replace(FragmentTransaction.java:200)
            at com.example.submission4.MainActivity.onCreate(MainActivity.java:71)
            at android.app.Activity.performCreate(Activity.java:7136)
            at android.app.Activity.performCreate(Activity.java:7127)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)</p>
  </blockquote>
  
  <p>MainActivity :</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  public static final String KEY_TITLE = "title";
  public static final String KEY_FRAGMENT = "fragment";
  
  private String title= null;
  
  Fragment fragment = new MovieFragment() ;
  
  private BottomNavigationView.OnNavigationItemSelectedListener onNavigationItemSelectedListener
          = new BottomNavigationView.OnNavigationItemSelectedListener() {
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
          switch (menuItem.getItemId()){
              case R.id.nav_movie:
                  fragment = new MovieFragment();
                  title = getString(R.string.movie);
                  getSupportActionBar().setTitle(title);
                  break;
              case R.id.nav_tv:
                  fragment = new TvFragment();
                  title = getString(R.string.tv);
                  getSupportActionBar().setTitle(title);
                  break;
              case R.id.nav_favorite:
                  fragment = new FavoriteFragment();
                  title = getString(R.string.favorite);
                  getSupportActionBar().setTitle(title);
  
          }
          return setFragment(fragment);
      }
  };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      setFragment(fragment);
      title = getString(R.string.movie);
      getSupportActionBar().setTitle(title);
  
      BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigation);
      bottomNavigationView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener);
  
      if (savedInstanceState == null){
          getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,fragment).commit();
          getSupportActionBar().setTitle(title);
      }else {
          fragment = getSupportFragmentManager().getFragment(savedInstanceState,KEY_FRAGMENT);
          title = savedInstanceState.getString(KEY_TITLE);
  
          getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, fragment).commit();
          getSupportActionBar().setTitle(title);
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_language,menu);
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(@NonNull MenuItem item) {
      if (item.getItemId() == R.id.change_language){
          Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
          startActivity(intent);
      }
      return super.onOptionsItemSelected(item);
  }
  
  
  public boolean setFragment(Fragment fragment){
      if (fragment != null){
          getSupportFragmentManager().beginTransaction()
                  .replace(R.id.frameLayout,fragment)
                  .commit();
          return true;
      }
  
      return false;
  }
  
  @Override
  public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
      outState.putString(KEY_TITLE, title);
      getSupportFragmentManager().putFragment(outState,KEY_FRAGMENT,fragment);
      super.onSaveInstanceState(outState, outPersistentState);
  
  }
  </code></pre>
  
  <p>error com.example.submission4.MainActivity.onCreate(MainActivity.java:71) reffer to  </p>
  
  <pre><code>   getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, fragment).commit();
  </code></pre>
  
  <p>Please help me, Thank you</p>