title: IllegalStateException: The specified child already has a parent
body: <p>When switching back to a view that I've already seen, the Activity crashes and throws an IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</p>
  
  <p>The stacktrace:</p>
  
  <pre><code>02-23 23:59:22.685    9254-9254/ldellabella3.gatech.edu.sustainability_in_computer_science E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: ldellabella3.gatech.edu.sustainability_in_computer_science, PID: 9254
      java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
              at android.view.ViewGroup.addViewInner(ViewGroup.java:3770)
              at android.view.ViewGroup.addView(ViewGroup.java:3623)
              at android.view.ViewGroup.addView(ViewGroup.java:3568)
              at android.view.ViewGroup.addView(ViewGroup.java:3544)
              at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:951)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
              at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
              at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
              at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
              at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
              at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
              at android.view.Choreographer.doCallbacks(Choreographer.java:612)
              at android.view.Choreographer.doFrame(Choreographer.java:581)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
              at android.os.Handler.handleCallback(Handler.java:733)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:146)
              at android.app.ActivityThread.main(ActivityThread.java:5487)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
              at dalvik.system.NativeStart.main(Native Method)
  02-24 00:02:57.133    9800-9800/ldellabella3.gatech.edu.sustainability_in_computer_science E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: ldellabella3.gatech.edu.sustainability_in_computer_science, PID: 9800
      java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
              at android.view.ViewGroup.addViewInner(ViewGroup.java:3770)
              at android.view.ViewGroup.addView(ViewGroup.java:3623)
              at android.view.ViewGroup.addView(ViewGroup.java:3568)
              at android.view.ViewGroup.addView(ViewGroup.java:3544)
              at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:951)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
              at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
              at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
              at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
              at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
              at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
              at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
              at android.view.Choreographer.doCallbacks(Choreographer.java:612)
              at android.view.Choreographer.doFrame(Choreographer.java:581)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
              at android.os.Handler.handleCallback(Handler.java:733)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:146)
              at android.app.ActivityThread.main(ActivityThread.java:5487)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The xml that I pass to setContentView() is simply</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.view.ViewPager
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>This is the activity that keeps crashing:</p>
  
  <pre><code>public class LearnMoreSlidesActivity extends FragmentActivity {
  
      private ViewPager viewPager;
      private PagerAdapter pagerAdapter;
      private ImageView[] slidesArray;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_learn_more);
  
          viewPager = (ViewPager) findViewById(R.id.pager);
          pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
          viewPager.setAdapter(pagerAdapter);
  
          slidesArray = new ImageView[]{
                  new ImageView(this),
                  new ImageView(this),
                  new ImageView(this)
          };
  
          slidesArray[0].setImageResource(R.drawable.earthzineimg);
          slidesArray[1].setImageResource(R.drawable.computingsustainability);
          slidesArray[2].setImageResource(R.drawable.computingandsustainability);
  
      }
  
      @Override
      public void onBackPressed() {
          if (viewPager.getCurrentItem() == 0) {
              // If the user is currently looking at the first step, allow the system to handle the
              // Back button. This calls finish() on this activity and pops the back stack.
              super.onBackPressed();
          } else {
              // Otherwise, select the previous step.
              viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
          }
      }
  
      private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
  
          public ScreenSlidePagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          //this is where we "inflate" fragment_learn_more with our ldellabella3.gatech.edu.sustainability_in_computer_science.ScreenSlideFragment
          @Override
          public Fragment getItem(int position) {
              ScreenSlideFragment slideFragment = new ScreenSlideFragment();
              slideFragment.setMySlide(slidesArray[position]);
              return slideFragment;
          }
  
          @Override
          public int getCount() {
              return 3;
          }
      }
  }
  </code></pre>
  
  <p>My ScreenSlideFragmentClass</p>
  
  <pre><code>public class ScreenSlideFragment extends Fragment {
  
      private ImageView myImg;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          return myImg;
      }
  
      public void setMySlide(ImageView img) {
          myImg = img;
      }
  }
  </code></pre>