title: Nested fragments in Android produces IllegalStateException: No activity
body: <p>I'm trying to nest fragments in Android SDK 17 but I keep getting an IllegalStateException stating that there is no Activity. I've seen other posts going back to 2011 about this being a bug. I can't believe that four years and many Android versions later this problem still exists. Can someone please show me how I can nest fragments without getting an exception?</p>
  
  <p>Here is the implementations I am using.</p>
  
  <pre><code>import android.app.Fragment;
  import android.app.FragmentManager;
  
  public class HomeActivity extends AppCompatActivity 
      implements AdapterView.OnItemClickListener,
      SinglePaneContainerFragment.OnFragmentInteractionListener {
  
  private Fragment containerFragment;
  ...
  
  containerFragment = new SinglePaneContainerFragment();
  
  getFragmentManager().beginTransaction().replace(
       R.id.content_frame, containerFragment, "single_pain").commit();
  
  FragmentManager childFragmentManager = containerFragment.getChildFragmentManager();
  
  childFragmentManager.beginTransaction().replace(
        R.id.fragment_placeholder1, new NestedFragment(), "featured").commit();
  </code></pre>
  
  <blockquote>
    <p>java.lang.IllegalStateException: No activity
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1069)
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
                at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
                at android.app.Fragment.performActivityCreated(Fragment.java:2128)
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
                at android.app.BackStackRecord.run(BackStackRecord.java:834)
                at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
                at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:145)
                at android.app.ActivityThread.main(ActivityThread.java:6837)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)</p>
  </blockquote>