title: NullPointer exception on setAdapter for Viewpager
body: <p>In a one screen I am using two viewPagers - one for image autoscroling and other for buttons  hand scrolling. Image autoscrolling was working perfectly fine, but when I added implementation for buttons on viewPager, my application started crashing for nullpointer on setAdapter, I am using fragmentPagerAdapter.
  For images autoslider I am using this reference code by
  <a href="https://github.com/JakeWharton/Android-ViewPagerIndicator" rel="nofollow">https://github.com/JakeWharton/Android-ViewPagerIndicator</a></p>
  
  <p>Here is my source code</p>
  
  <p>layout xml file simple_circles.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;!-- android:layout_weight="0.01" --&gt;
  
      &lt;SearchView
          android:id="@+id/search_view"
          android:layout_width="fill_parent"
          android:layout_height="80dp" &gt;
      &lt;/SearchView&gt;
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/pager"
          android:layout_width="fill_parent"
          android:layout_height="400dp"&gt;
      &lt;/android.support.v4.view.ViewPager&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/pager_for_buttons"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" &gt;       
  
      &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p>fragment for adding buttons on slider -</p>
  
  <pre><code>    public class ScreenSlidePageFragment extends Fragment {
  
      public static final String ARG_PAGE = "page";
  
  
      private int mPageNumber;
  
  
      public static Fragment create(int pageNumber) {
          ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
          Bundle args = new Bundle();
          args.putInt(ARG_PAGE, pageNumber);
          fragment.setArguments(args);
          return fragment;
      }
  
      public ScreenSlidePageFragment() {
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mPageNumber = getArguments().getInt(ARG_PAGE);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
           // Inflate the layout containing a title and body text.
          Button music_button = new Button(getActivity());
          music_button.setText("Music");
  
          Button news_button = new Button(getActivity());
          news_button.setText("News");
  
          Button videos_button = new Button(getActivity());
          videos_button.setText("Videos");
          Button photos_button = new Button(getActivity());
          photos_button.setText("Photos");
          LinearLayout layout = new LinearLayout(getActivity());
          layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
          //layout.setGravity(Gravity.CENTER);
          layout.addView(music_button);
          layout.addView(news_button);
          layout.addView(videos_button);
          layout.addView(photos_button);
  
          return layout;
  
  
  
      }
  
  
      public int getPageNumber() {
          return mPageNumber;
      }
  }
  </code></pre>
  
  <p>Activity class and adapter for viewPager - </p>
  
  <pre><code>public class SampleCirclesDefault extends FragmentActivity {
  
      // Initialization
  
      TestFragmentAdapter mAdapter;
      ViewPager mPager;
      PageIndicator mIndicator;
      Bitmap bitmap;
      ArrayList&lt;String&gt; bandImagesList;
      ImageView build_bandapp_img;
      boolean pagerMoved;
      Runnable Update;
      Handler h;
      long ANIM_VIEWPAGER_DELAY;
      Handler handler;
      int NUM_PAGES = 5;
      ViewPager buttonPager;
      ScreenSlidePagerAdapter buttonAdapter;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // No action bar
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
              **setContentView(R.layout.simple_circles);**
          build_bandapp_img = (ImageView) findViewById(R.id.imageView_for_webview);
          build_bandapp_img.setOnClickListener(new OnClickListener() {
              // Build bandapp button
              @Override
              public void onClick(View v) {
  
                  Intent i = new Intent(SampleCirclesDefault.this,
                          BandDetailedActivity.class);
                  startActivity(i);
              }
          });
  
          mAdapter = new TestFragmentAdapter(getSupportFragmentManager());// adapter
                                                                          // for
                                                                          // viewpager
  
          mPager = (ViewPager) findViewById(R.id.pager);
          mPager.setAdapter(mAdapter);
          buttonAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
          //buttonAdapter = new AdapterForFragmentOfButtonSlider(getSupportFragmentManager());
          buttonPager = (ViewPager)findViewById(R.id.pager_for_buttons);
          buttonPager.setAdapter(buttonAdapter); //***error -NullPointerException***//
  
          mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
          mIndicator.setViewPager(mPager);// dot dot indicator
          buttonPager.setCurrentItem(1); 
          handler = new Handler();
          // autoscrolling of view pager
          Update = new Runnable() {
  
              int currentPage = mPager.getCurrentItem();
  
              public void run() {
                  if (currentPage == NUM_PAGES - 1) {
                      currentPage = 0;
                  }
                  mPager.setCurrentItem(currentPage++, true);
              }
          };
  
          Timer swipeTimer = new Timer();
          swipeTimer.schedule(new TimerTask() {
  
              @Override
              public void run() {
                  handler.post(Update);
              }
          }, 100, 5000);
  
      }
  
       private class ScreenSlidePagerAdapter extends FragmentPagerAdapter {
              public ScreenSlidePagerAdapter(FragmentManager fragmentManager) {
                  super(fragmentManager);
              }
  
              @Override
              public Fragment getItem(int position) {
                  return ScreenSlidePageFragment.create(position);
              }
  
              @Override
              public int getCount() {
                  return NUM_PAGES;
              }
          }
      }
  </code></pre>
  
  <p>Stack trace </p>
  
  <pre><code>01-23 13:56:57.067: W/dalvikvm(18861): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
  01-23 13:56:57.098: E/AndroidRuntime(18861): FATAL EXCEPTION: main
  01-23 13:56:57.098: E/AndroidRuntime(18861): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.viewpagerindicator.sample/com.viewpagerindicator.sample.SampleCirclesDefault}: java.lang.NullPointerException
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.os.Looper.loop(Looper.java:137)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread.main(ActivityThread.java:5041)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at java.lang.reflect.Method.invoke(Method.java:511)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at dalvik.system.NativeStart.main(Native Method)
  01-23 13:56:57.098: E/AndroidRuntime(18861): Caused by: java.lang.NullPointerException
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at com.viewpagerindicator.sample.SampleCirclesDefault.onCreate(SampleCirclesDefault.java:85)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.Activity.performCreate(Activity.java:5104)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  01-23 13:56:57.098: E/AndroidRuntime(18861):    ... 11 more
  01-23 13:57:13.356: I/Process(18861): Sending signal. PID: 18861 SIG: 9
  </code></pre>
  
  <p>I have pointed exactly where I am getting error. </p>
  
  <p>Please help me to resolve this error, thanks in advance.</p>