title: Android's IllegalStateException in dynamic rows creation
body: <p>I followed this fellow <a href="https://stackoverflow.com/questions/5183968/how-to-add-rows-dynamically-into-table-layout">here</a> and ended up getting the following error. As far as I understand I am not required to run new <code>TableLayout()</code>, neither new <code>Textview()</code> on runtime.</p>
  <pre><code>04-14 16:11:55.232: E/AndroidRuntime(24014): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.opencv.samples.fd/org.opencv.samples.fd.StatsActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.os.Looper.loop(Looper.java:137)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread.main(ActivityThread.java:4898)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at dalvik.system.NativeStart.main(Native Method)
  04-14 16:11:55.232: E/AndroidRuntime(24014): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.view.ViewGroup.addViewInner(ViewGroup.java:3618)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.view.ViewGroup.addView(ViewGroup.java:3489)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.widget.TableLayout.addView(TableLayout.java:425)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.view.ViewGroup.addView(ViewGroup.java:3434)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.widget.TableLayout.addView(TableLayout.java:407)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.view.ViewGroup.addView(ViewGroup.java:3410)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.widget.TableLayout.addView(TableLayout.java:398)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at org.opencv.samples.fd.StatsActivity.doStats(StatsActivity.java:202)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at org.opencv.samples.fd.StatsActivity.onCreate(StatsActivity.java:64)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.Activity.performCreate(Activity.java:5206)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
  04-14 16:11:55.232: E/AndroidRuntime(24014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
  </code></pre>
  <p>Here's the code snippet:</p>
  <pre><code>public void doStats()
  {       
      TableLayout table = (TableLayout) StatsActivity.this.findViewById(R.id.TableLayout01);
          
      String[] pattern =  splitPattern();         
      for (int i = 0; i &lt; pattern.length; i++)
      {       
  
          // create a new TableRow
          TableRow row = (TableRow) LayoutInflater.from(StatsActivity.this).inflate(R.layout.attrib_row, null);
            
          String[] sessions = pattern[i].split(&quot;/&quot;);
          
          for (int y = 0; y &lt; sessions.length; y++)
          {
              ((TextView)row.findViewById(R.id.TextView01)).setText(String.valueOf(sessions[0].toString()));
              ((TextView)row.findViewById(R.id.TextView02)).setText(String.valueOf(sessions[1].toString()));
              table.addView(row);             
          }                       
      }
      table.requestLayout(); 
  }
  </code></pre>
  <p>Please note that at the moment I am running <code>doStats()</code> from <code>onCreate</code>.
  Any inside will be much appreciated.</p>