title: Fragment no longer exists for key f0: index 0
body: <pre><code>FATAL EXCEPTION: main
        Process: com.riyadbankacademy, PID: 23795
        Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
        java.lang.IllegalStateException: Fragment no longer exists for key f0: index 0
        at android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:879)
        at android.support.v4.app.FragmentStatePagerAdapter.restoreState(FragmentStatePagerAdapter.java:215)
        at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1481)
        at android.view.View.dispatchRestoreInstanceState(View.java:14756)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3121)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3127)
        at android.view.View.restoreHierarchyState(View.java:14734)
        at android.support.v4.app.Fragment.restoreViewState(Fragment.java:475)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1329)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
        at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5461)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>
  
  <hr>
  
  <pre><code>public class LibraryViewPagerAdapter extends FragmentStatePagerAdapter {
      private int size=0;
  
      public LibraryViewPagerAdapter(FragmentManager fm, int size) {
          super(fm);
          this.size = size;
      }
  
      @Override
      public Fragment getItem(int position) {
          Log.e("LibraryViewPagerAdapter=getItem", position + "");
          return new LibraryPageFragment(position);
      }
  
      @Override
      public int getCount() {
          return size;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>I have 4 fragments. And Navigation Drawer. After I moved from 1 fragment to 2 for the first time everything was fine. After 2 times I moved from 1 fragment to 2, too, everything was fine.</p>
  
  <p>But as soon as I tried to go from 1 fragment to 2 fragment 3 times. That got this error.</p>
  
  <p>I understand the problem with ViewPager. But where to dig I do not know. Need help developers</p>