title: java.lang.IllegalArgumentException: No view found for id 0x7f0700ca
body: <p>I have a login fragment and want to replace the fragment after successful login.
  I tried to replace the fragment inside the login fragment.</p>
  
  <p><strong>First</strong> I tried to call the following code inside the fragment (onActivityCreated,onCreateView,onStart)</p>
  
  <pre><code>getSupportFragmentManager().beginTransaction()
              .replace(R.id.mainframelayout, ReservationFragment.newInstance())
              .commitNow();
  </code></pre>
  
  <p>My <strong>second way</strong> was to try to call a activity method:</p>
  
  <pre><code>public void replaceFragments(Class fragmentClass) {
      Fragment fragment = null;
      try {
          fragment = (Fragment) fragmentClass.newInstance();
      } catch (Exception e) {
          e.printStackTrace();
      }
      getSupportFragmentManager().beginTransaction()
          .replace(R.id.mainframelayout, fragment)
          .commitNow();
  }
  </code></pre>
  
  <p><strong>Activity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_activity);
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .replace(R.id.mainframelayout, LoginFragment.newInstance())
                      .commitNow();
          }
      }
  
      public void replaceFragments(Class fragmentClass) {
          Fragment fragment = null;
          try {
              fragment = (Fragment) fragmentClass.newInstance();
          } catch (Exception e) {
              e.printStackTrace();
          }
          getSupportFragmentManager().beginTransaction()
              .replace(R.id.mainframelayout, fragment)
              .commitNow();
      }
  }
  </code></pre>
  
  <p><strong>Activity xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainframelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>The following error always came up:</p>
  
  <blockquote>
    <p>E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.retrofit, PID: 15872
        java.lang.IllegalArgumentException: No view found for id 0x7f07007c (com.example.retrofit:id/mainframelayout) for fragment
    ReservationFragment{6e639e1} (59264633-2704-48d9-872d-551ef1142b68)
    id=0x7f07007c}
            at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:305)
            at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1185)
            at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
            at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
            at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
            at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
            at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2167)
            at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1990)
            at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1945)
            at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1816)
            at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:297)
            at com.example.retrofit.MainActivity.replaceFragments(MainActivity.java:33)
            at com.example.retrofit.ui.login.LoginFragment$1.onClick(LoginFragment.java:54)
            at android.view.View.performClick(View.java:6597)
            at android.view.View.performClickInternal(View.java:6574)
            at android.view.View.access$3100(View.java:778)
            at android.view.View$PerformClick.run(View.java:25885)
            at android.os.Handler.handleCallback(Handler.java:873)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6669)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    I/Process: Sending signal. PID: 15872 SIG: 9</p>
  </blockquote>
  
  <p>I've tried many things, but I haven't found a solution.
  I understand that the fragment may not have access to the activity xml, but why the second way not work I dont understand.</p>