title: How to set up tabs with view pager in android?
body: <p>I have followed the following <a href="https://guides.codepath.com/android/ViewPager-with-FragmentPagerAdapter" rel="nofollow">instructions</a> in order to get sliding tabs with a view pager. </p>
  
  <p>Here is my onCreate method:</p>
  
  <pre><code>mViewPager.setAdapter(new NavigationPagerAdapter(getSupportFragmentManager()));
  mTabLayout.setupWithViewPager(mViewPager);
  </code></pre>
  
  <p>Here is my navigation pager adapter:</p>
  
  <pre><code>public static class NavigationPagerAdapter extends FragmentPagerAdapter {
      private static final int NUM_ITEMS = 3;
  
      public NavigationPagerAdapter(FragmentManager fragmentManager) {
          super(fragmentManager);
      }
  
      // Returns total number of pages
      @Override
      public int getCount() {
          return NUM_ITEMS;
      }
  
      // Returns the fragment to display for that page
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0: // Fragment # 0 - This will show FirstFragment
                  return new FeedFragment();
              default:
                  return null;
          }
      }
  
      // Returns the page title for the top indicator
      @Override
      public CharSequence getPageTitle(int position) {
          return "Page " + position;
      }
  }
  </code></pre>
  
  <p>Here is my content_main.xml activity layout:</p>
  
  <pre><code>&lt;android.support.design.widget.TabLayout
      android:id="@+id/navigation_sliding_tabs"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:tabMode="scrollable"/&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/navigation_pager"
      android:layout_width="match_parent"
      android:layout_height="0px"
      android:layout_weight="1"/&gt;
  </code></pre>
  
  <p>This is the error I get when running the code:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
  </code></pre>
  
  <p>I am not sure if the error lies in the pager adapter but it seems the fragment manager is causing trouble.</p>