title: Android/Java Error: "java.lang.IllegalStateException: The specified child already has a parent"
body: <p>I'm in the process of building a simple recycler and trying to test what I have so far. (new to android) I've looked into it an I think the error lies in my "MainActivity.java" or the adapter "MyAdapter.java" but I can't get it to resolve. Any input would be amazing. I'm am receiving this error in my logcat:</p>
  
  <pre><code>07-16 15:15:55.743 2997-2997/com.example.duncan.recyclerviewproject E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: com.example.duncan.recyclerviewproject, PID: 2997
                                                                                    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:3949)
                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:3799)
                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:3740)
                                                                                        at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:727)
                                                                                        at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)
                                                                                        at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:7921)
                                                                                        at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7879)
                                                                                        at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7867)
                                                                                        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
                                                                                        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1502)
                                                                                        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
                                                                                        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3625)
                                                                                        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3354)
                                                                                        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3886)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1197)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:434)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                                                                                        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                                                                                        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                                        at android.view.View.layout(View.java:16067)
                                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5051)
                                                                                        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2122)
                                                                                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1879)
                                                                                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1090)
                                                                                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5982)
                                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:781)
                                                                                        at android.view.Choreographer.doCallbacks(Choreographer.java:592)
                                                                                        at android.view.Choreographer.doFrame(Choreographer.java:560)
                                                                                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:767)
                                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:135)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5484)
                                                                                        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:984)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
  </code></pre>
  
  <p>My MainActivity.java:</p>
  
  <pre><code>package com.example.duncan.recyclerviewproject;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
  
      private RecyclerView recyclerView;
      private RecyclerView.Adapter adapter;
  
      private List&lt;ListItem&gt; listItems;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          listItems = new ArrayList&lt;&gt;();
  
          for(int i = 0; i&lt;=10; i++){
              ListItem listItem = new ListItem(
                      "heading " + (i+1),
                      "Lorem ipsum dummy text"
              );
  
              listItems.add(listItem);
          }
  
          adapter = new MyAdapter(listItems, this);
  
          recyclerView.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>MyAdapter.java:</p>
  
  <pre><code>package com.example.duncan.recyclerviewproject;
  
  import android.content.Context;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import java.util.List;
  
  /**
   * Created by Duncan on 7/16/17.
   */
  
  public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
      private List&lt;ListItem&gt; listItems;
      private Context context;
  
      public MyAdapter(List&lt;ListItem&gt; listItems, Context context) {
          this.listItems = listItems;
          this.context = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.list_item, parent);
          return new ViewHolder(v);
  
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          ListItem listItem = listItems.get(position);
  
          holder.textViewHead.setText(listItem.getHead());
          holder.textViewDesc.setText(listItem.getDesc());
      }
  
      @Override
      public int getItemCount() {
          return listItems.size();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
  
          public TextView textViewHead;
          public TextView textViewDesc;
  
          public ViewHolder(View itemView) {
              super(itemView);
  
              textViewHead = (TextView) itemView.findViewById(R.id.textViewHead);
              textViewDesc = (TextView) itemView.findViewById(R.id.textViewDesc);
  
  
   }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I've created 2 XML Files</p>
  
  <p>list_items.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="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;android.support.v7.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;LinearLayout
              android:padding="16dp"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;
  
              &lt;TextView
                  android:id="@+id/textViewHead"
                  android:text="Heading"
                  android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" /&gt;
  
              &lt;TextView
                  android:id="@+id/textViewDesc"
                  android:text="Body"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" /&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>activity_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.duncan.recyclerviewproject.MainActivity"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="784dp"
          android:layout_height="1127dp"
          tools:layout_editor_absoluteY="8dp"
          tools:layout_editor_absoluteX="8dp"&gt;&lt;/android.support.v7.widget.RecyclerView&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>