title: Adding TextView for each item in array
body: <p>I am trying to split sqlite column into an array and then add a <code>TextView</code> for each item of the array.  Below is my function to add a <code>TextView</code> for each item in array:</p>
  
  <pre><code>private void BuildTable() {
  
      sqlcon.open();
      Cursor c = sqlcon.readEntry();
  
      int rows = c.getCount();
      int cols = c.getColumnCount();
      String[] array;
      c.moveToFirst();
  
      // outer for loop
      for (int i = 0; i &lt; rows; i++) {
  
          TableRow row = new TableRow(this);
          row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT));
  
          // inner for loop
          for (int j = 0; j &lt; cols; j++) {
  
              TextView tv = new TextView(this);
              tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
          //    tv.setBackgroundResource(R.drawable.cell_shape);
              tv.setGravity(Gravity.CENTER);
              tv.setTextSize(18);
              tv.setPadding(0, 5, 0, 5);
              array = c.getString(1).split(",");
              for (int k = 0; k &lt; array.length; k++) {
                  tv.setText(array[k]);
                 row.addView(tv);
  
             }
  
          }
  
          c.moveToNext();
  
          table_layout.addView(row);
  
      }
      sqlcon.close();
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.logquiz.thequiz.logquiz/com.logquiz.thequiz.logquiz.RulesActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</p>
  </blockquote>