title: Android Exception "The specified child already has a parent..."
body: <p>I m getting exception as follow. Can anybody help me?</p>
  
  <blockquote>
    <p>06-16 11:32:48.237: ERROR/AndroidRuntime(9223):
    java.lang.IllegalStateException: The specified child already has a
    parent. You must call removeView() on the child's parent first.</p>
  </blockquote>
  
  <pre><code>        06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.ViewGroup.addView(ViewGroup.java:1865)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.ViewGroup.addView(ViewGroup.java:1822)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.ViewGroup.addView(ViewGroup.java:1802)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at com.mVisum_philips.MainECGActivity.popupEvent(MainECGActivity.java:628)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at com.mVisum_philips.MainECGActivity$1.onClick(MainECGActivity.java:195)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.View.performClick(View.java:2408)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.view.View$PerformClick.run(View.java:8816)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.os.Handler.handleCallback(Handler.java:587)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.os.Handler.dispatchMessage(Handler.java:92)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.os.Looper.loop(Looper.java:123)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at android.app.ActivityThread.main(ActivityThread.java:4627)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at java.lang.reflect.Method.invokeNative(Native Method)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at java.lang.reflect.Method.invoke(Method.java:521)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
          06-16 11:32:48.237: ERROR/AndroidRuntime(9223):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Source code for <em>screen_pop_up.xml</em>:        </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
             &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent"&gt;
              &lt;LinearLayout android:id="@+id/headerLin" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;
                  &lt;RelativeLayout android:layout_height="wrap_content" android:id="@+id/relativeLayout1" android:layout_width="fill_parent"&gt;
                      &lt;Button android:layout_width="wrap_content" android:id="@+id/button1" android:layout_height="wrap_content" android:text="Done"&gt;&lt;/Button&gt;
                      &lt;LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_alignParentRight="true"&gt;
                          &lt;Button android:layout_height="wrap_content" android:background="@drawable/h_scale" android:id="@+id/button2" android:layout_width="wrap_content" android:padding="15sp"&gt;&lt;/Button&gt;
                          &lt;Button android:layout_height="wrap_content" android:background="@drawable/v_scale" android:id="@+id/button3" android:layout_width="wrap_content" android:padding="14sp"&gt;&lt;/Button&gt;
                      &lt;/LinearLayout&gt;
                  &lt;/RelativeLayout&gt;
             &lt;/LinearLayout&gt;
  
  
          &lt;LinearLayout android:id="@+id/linLin" android:layout_height="300sp" android:layout_width="250sp"&gt;
          &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Source code where i m getting the exception is as follows:</p>
  
  <pre><code>final Dialog myDialog = new Dialog(MainECGActivity.this);
                  myDialog.setContentView(R.layout.screen_pop_up);
                  myDialog.setTitle("My Dialog");
  
                  LinearLayout myLin = (LinearLayout) myDialog.findViewById(R.id.linLin);
                  **myLin.addView(ECGField.get(0));**
  
                  myDialog.setCancelable(true);
                  Button button = (Button) myDialog.findViewById(R.id.button1);
                  button.setOnClickListener(new OnClickListener() {
                  @Override
                      public void onClick(View v) {
                      myDialog.dismiss();
                      }
                  });
  
                  myDialog.show();
  </code></pre>
  
  <p>I have gone through many threads here but I am missing something.
  Thanks in advance.</p>