title: How to add TableRow from xml to TableLayout programmatically?
body: <p>Im new to Android and I'm trying to add a TableRow, which I already made with xml, to a TableLayout programmatically. I'm getting Force Closes, most are NullPointerExcpetions.</p>
  
  <p>Here's my java class</p>
  
  <pre><code>public class DayFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.subjects_list, container, false);
  
  
      TableLayout tl = (TableLayout) view.findViewById(R.id.tl);
      TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
  
              tl.addView(tr); //not working, obviously im missing something
  
      //xml parsing stuff
  
              return view;
   }
  }
  </code></pre>
  
  <p>This is my layout with the TableLayout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/horizontalScrollView1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingTop="5dp" &gt;
  
  &lt;ScrollView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:fillViewport="true"
      android:orientation="vertical" &gt;
  
      &lt;TableLayout
          android:id="@+id/tl"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
          &lt;include
              android:id="@+id/header"
              layout="@layout/table_header" /&gt;
  
          &lt;include android:id="@+id/h_divider"
              layout="@layout/horizontal_divider"/&gt;
  
  
  
  
      &lt;/TableLayout&gt;
  &lt;/ScrollView&gt;
  
  &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>And the TableRow:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableRow xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/tr_row"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" &gt;
  
  &lt;TextView
      android:id="@+id/tv_hour"
      android:layout_weight="1"
      android:gravity="center"
      android:padding="8dp"
      android:textSize="15sp"
      android:textStyle="bold" /&gt;
  
  &lt;View
      android:layout_weight="1"
      android:background="@drawable/vertical_cell_divider" /&gt;
  
  &lt;TextView
      android:id="@+id/tv_subject"
      android:layout_weight="1"
      android:gravity="left"
      android:padding="8dp"
      android:textSize="18sp" /&gt;
  
  &lt;View
      android:layout_weight="1"
      android:background="@drawable/vertical_cell_divider" /&gt;
  
  &lt;TextView
      android:id="@+id/tv_start"
      android:layout_weight="1"
      android:gravity="left"
      android:padding="8dp"
      android:textSize="18sp" /&gt;
  
  &lt;TextView
      android:id="@+id/tv_bar"
      android:layout_weight="1"
      android:gravity="left"
      android:textSize="18sp" /&gt;
  
  &lt;TextView
      android:id="@+id/tv_end"
      android:layout_weight="1"
      android:gravity="left"
      android:padding="8dp"
      android:textSize="18sp" /&gt;
  
  &lt;/TableRow&gt;
  </code></pre>
  
  <p>I tried lots of different ways to achieve it but still nothing.</p>