title: Getting error while adding fragments dynamically -java.lang.IllegalStateException:
body: <p>I'm working on 3.0 for the first time.
  I want to <strong>add fragments dynamically</strong> , <strong>but its shown error:-</strong></p>
  
  <pre><code>10-18 18:29:11.215: ERROR/AndroidRuntime(3550): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  </code></pre>
  
  <p><strong>XML code</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/frags"&gt;
  
  &lt;ListView
          android:id="@+id/number_list"
          android:layout_width="250dip"
          android:layout_height="match_parent" /&gt;
  
  &lt;FrameLayout
          android:id="@+id/the_frag"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Activity</strong></p>
  
  <pre><code>public class FragmentExampleActivity extends Activity implements
      OnItemClickListener {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      ListView l = (ListView) findViewById(R.id.number_list);
      ArrayAdapter&lt;String&gt; numbers = new ArrayAdapter&lt;String&gt;(
              getApplicationContext(), android.R.layout.simple_list_item_1,
              new String[] { "one", "two", "three", "four", "five", "six" });
      l.setAdapter(numbers);
      l.setOnItemClickListener(this);
  }
  
  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
      Fragment f = new FragmentExample();
  
      FragmentTransaction ft = getFragmentManager().beginTransaction();       
      ft.replace(R.id.the_frag, f);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
      ft.addToBackStack(null);
      ft.commit();
  
  }
  }
  
  
  public class FragmentExample extends Fragment {
  private int nAndroids=1;
  
  public FragmentExample() {
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) {
      int n;
  
      View l = inflater.inflate(R.layout.textlay,container);
      TextView tv = (TextView) l.findViewById(R.id.textView1);
      tv.setText("value "+nAndroids);
  
      return l;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Plz put some light on , where i'm going wrong :(</p>