title: NullPointerException with Fragment and ViewPager
body: <p>I have some problems with my code. I have a NullPointerException in the code below.
  I'm trying to create a swipe between 3 differents fragments.</p>
  
  <p>I don't understand where is my mistake so please help me :p </p>
  
  <p>DummyFragment.java :</p>
  
  <pre><code>package com.example.testslide;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  public class DummyFragment  extends Fragment {
  
      public static DummyFragment newInstance(String chaine) {
          DummyFragment fragment = new DummyFragment();
          Bundle args = new Bundle();
          args.putString("KEY_STRING", chaine);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.milieu, container);
          TextView textView = (TextView) v.findViewById(R.id.textView1);
          Bundle args = getArguments();
          textView.setText(args.getString("KEY_STRING"));
          return v;
      }
  
  }
  </code></pre>
  
  <p>ViewPagerAdapter</p>
  
  <pre><code>package com.example.testslide;
  
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  
  public class ViewPagerAdapter extends FragmentPagerAdapter {
      public ViewPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int pos) {
          switch(pos) {
          case 1: return DummyFragment.newInstance("Je suis le premier écran !");
          case 2: return DummyFragment.newInstance("Je suis le second écran !");
          case 3: return DummyFragment.newInstance("Je suis le troisième écran !");
          }
          return null;
      }
  
      @Override
      public int getCount() {
          return 3;
      }
  }
  </code></pre>
  
  <p>ViewPagerActivity :</p>
  
  <pre><code>package com.example.testslide;
  
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.ViewPager;
  
  
  public class ViewPagerActivity extends FragmentActivity {
      private ViewPagerAdapter mSectionsPagerAdapter;
      private ViewPager mViewPager;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.viewpager);
          // Set up the adapter.
          mSectionsPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
  
          // Set up the ViewPager with the sections adapter.
          mViewPager = (ViewPager) findViewById(R.id.viewPager);
          mViewPager.setAdapter(mSectionsPagerAdapter);
      }
  }
  </code></pre>
  
  <p>viewpager.xml :</p>
  
  
  
  <pre><code>&lt;android.support.v4.view.ViewPager
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/viewPager"&gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p>milieu.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_margin="20dp"
          android:text="Page du milieu" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>LogCat :</p>
  
  <pre><code>07-10 08:25:26.211: E/AndroidRuntime(607): FATAL EXCEPTION: main
  07-10 08:25:26.211: E/AndroidRuntime(607): java.lang.NullPointerException
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.view.ViewPager.populate(ViewPager.java:982)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.View.measure(View.java:10828)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.View.measure(View.java:10828)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.View.measure(View.java:10828)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1889)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.View.measure(View.java:10828)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.ViewRoot.performTraversals(ViewRoot.java:938)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.view.ViewRoot.handleMessage(ViewRoot.java:2040)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.os.Handler.dispatchMessage(Handler.java:99)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.os.Looper.loop(Looper.java:132)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at android.app.ActivityThread.main(ActivityThread.java:4123)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at java.lang.reflect.Method.invokeNative(Native Method)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at java.lang.reflect.Method.invoke(Method.java:491)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
  07-10 08:25:26.211: E/AndroidRuntime(607):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>