title: IllegalArgumentException when trying to populate fragments for a ViewPager within a DialogFragment
body: <p>I'm launching a DialogFragment which has a ViewPager in it, which in turn will have multiple fragments in it.</p>
  
  <p>When i try to actually add the fragments inside the ViewPager though, I get an IllegalArgumentException saying the view is not found:</p>
  
  <pre><code>03-14 16:44:11.989    3617-3617/com.mycompany.app.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.IllegalArgumentException: No view found for id 0x7f090146 for fragment GuestProfileQuestionnaireStep1Fragment{5375fa28 #3 id=0x7f090146}
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:823)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
              at android.app.BackStackRecord.run(BackStackRecord.java:635)
              at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
              at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:437)
              at android.support.v13.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
              at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
              at android.view.View.measure(View.java:15172)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
              at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
              at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
              at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
              at android.view.View.measure(View.java:15172)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
              at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
              at android.view.View.measure(View.java:15172)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
              at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
              at android.view.View.measure(View.java:15172)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
              at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
              at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
              at android.view.View.measure(View.java:15172)
              at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
              at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1075)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
              at android.view.Choreographer.doCallbacks(Choreographer.java:555)
              at android.view.Choreographer.doFrame(Choreographer.java:525)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
              at android.os.Handler.handleCallback(Handler.java:615)
              at android.os.Handler.dispatchMessage(Handler.java:92)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4745)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>So basically I have the following flow:</p>
  
  <p>Activity --> DialogFragment (has a) > ViewPager --> calls Adapter that in turn calls multiple fragments. Here's some relevant code:</p>
  
  <h3>DialogFragment</h3>
  
  <pre><code>public class GuestProfileQuestionnaireContainerDialogFragment
          extends DialogFragment  {
  
      @InjectView(R.id.guest_profile_questionnaire_pager) ViewPager mProfileQuestionnairePager;
  
      // ...
  
      @Override
      public View onCreateView(LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState) {
          View layoutView = inflater.inflate(R.layout.fragment_guest_profile_questionnaire_container,
                                             container,
                                             false);
          ButterKnife.inject(this, layoutView);
  
          // ...
          setupProfileQuestionnaire();
  
          return layoutView;
      }
  
      // ...
  
      private void setupProfileQuestionnaire() {
          mProfileQuestionnairePager.setAdapter(new GuestProfileQuestionnairePagerAdapter(getFragmentManager()));
      }
  }
  </code></pre>
  
  <h3>layout (nothing fancy here)</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;FrameLayout ...
  
      &lt;TextView ...
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/guest_profile_questionnaire_pager"
          android:layout_height="match_parent"
          android:layout_width="match_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h3>PagerAdapter that populates fragments</h3>
  
  <pre><code>public class GuestProfileQuestionnairePagerAdapter
          extends FragmentStatePagerAdapter {
  
      public static final int TOTAL_NUM_OF_STEPS = 1;
  
      public GuestProfileQuestionnairePagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public int getCount() {
          return TOTAL_NUM_OF_STEPS;
      }
  
      @Override
      public Fragment getItem(int position) {
  
          switch (position) {
              case 0:
                  return GuestProfileQuestionnaireStep1Fragment.newInstance();
          }
  
          return null;
      }
  }
  </code></pre>
  
  <h3>Fragment</h3>
  
  <pre><code>public class GuestProfileQuestionnaireStep1Fragment
          extends Fragment {
  
      private GuestProfileQuestionnaireStep1Fragment() {
          super();
      }
  
      public static GuestProfileQuestionnaireStep1Fragment newInstance() {
          return new GuestProfileQuestionnaireStep1Fragment();
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_guest_profile_questionnaire_step1,
                                  container,
                                  false);
      }
  }
  </code></pre>
  
  <p>I don't get an exception when my ViewPager is empty. So basically when the ViewPAger alone is inflated there's no problem. However the minute I return an actual fragment within the ViewPager, I get the exception.</p>