title: The specified child already has a parent. You must call removeView() on the child's parent first
body: <p>I am doing a little exercise about a application you that put your name, and it returns &quot;hello (the name you put)&quot;. But after i push the button i get the error &quot;The specified child already has a parent. You must call removeView() on the child's parent first&quot;</p>
  <p><strong>MainActivity.java</strong></p>
  <pre class="lang-java prettyprint-override"><code>package com.example.holaamigos;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.*;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  
  public class MainActivity extends Activity {
      public final static String EXTRA_SALUDO = &quot;com.example.holaamigos.SALUDO&quot;;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          
          final EditText txtNombre = (EditText)findViewById(R.id.TxtNombre);
          final Button btnHola = (Button)findViewById(R.id.BtnHola);
              
              btnHola.setOnClickListener(new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Intent intent = new Intent(MainActivity.this, ActivitySaludo.class);
                      String saludo = txtNombre.getText().toString();
                      intent.putExtra(EXTRA_SALUDO, saludo);
                      startActivity(intent);
          }
                  
      });
              
      }
                      
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  <p><strong>ActivitySaludo.java</strong></p>
  <pre class="lang-java prettyprint-override"><code>package com.example.holaamigos;
  
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class ActivitySaludo extends Activity {
      
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_saludo);
          
          Intent intent = getIntent();
          String saludo = intent.getStringExtra(MainActivity.EXTRA_SALUDO);
          
          //TextView txt = new TextView(this);
          //txt.setText(20);
          //txt.setText(saludo);
          
          TextView txtCambiado = (TextView) findViewById(R.id.TxtSaludo);
          txtCambiado.setText(saludo);
          setContentView(txtCambiado);
      }
  
  }
  </code></pre>
  <p><strong>activity_saludo.xml</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot; &gt;
      
      &lt;TextView 
          android:id=&quot;@+id/TxtSaludo&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;&quot; /&gt;
      
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/LinearLayout1&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot; &gt;
  
      &lt;TextView
          android:id=&quot;@+id/LblNombre&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;@string/nombre&quot; /&gt;
      
      &lt;EditText
          android:id=&quot;@+id/TxtNombre&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:inputType=&quot;text&quot; /&gt;
      
      &lt;Button 
          android:id=&quot;@+id/BtnHola&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;@string/hola_apy&quot;
          android:onClick=&quot;enviarSaludo&quot;/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p><strong>LogCat</strong></p>
  <pre class="lang-java prettyprint-override"><code>10-10 16:12:18.470: D/AndroidRuntime(810): Shutting down VM
  10-10 16:12:18.470: W/dalvikvm(810): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
  10-10 16:12:18.586: E/AndroidRuntime(810): FATAL EXCEPTION: main
  10-10 16:12:18.586: E/AndroidRuntime(810): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.holaamigos/com.example.holaamigos.ActivitySaludo}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.os.Handler.dispatchMessage(Handler.java:99)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.os.Looper.loop(Looper.java:137)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread.main(ActivityThread.java:5041)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at java.lang.reflect.Method.invokeNative(Native Method)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at java.lang.reflect.Method.invoke(Method.java:511)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at dalvik.system.NativeStart.main(Native Method)
  10-10 16:12:18.586: E/AndroidRuntime(810): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.view.ViewGroup.addView(ViewGroup.java:3210)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.view.ViewGroup.addView(ViewGroup.java:3186)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:289)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:279)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.Activity.setContentView(Activity.java:1901)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at com.example.holaamigos.ActivitySaludo.onCreate(ActivitySaludo.java:25)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.Activity.performCreate(Activity.java:5104)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  10-10 16:12:18.586: E/AndroidRuntime(810):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  10-10 16:12:18.586: E/AndroidRuntime(810):  ... 11 more
  10-10 16:12:18.856: D/dalvikvm(810): GC_CONCURRENT freed 134K, 10% free 2630K/2908K, paused 73ms+83ms, total 237ms
  </code></pre>