title: Add layout resource programmatically
body: <p>I have a custom layout called "debug.xml" in folder "layout/" which is desired to add programmatically into a predefined Layout in activity_main.xml called centerLayout. The "debug.xml" is something like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/debug_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;EditText
              android:id="@+id/commandEditText"
              android:layout_width="0dp"
              android:layout_height="50dp"
              android:layout_weight="1"
              android:gravity="center_vertical"
              android:inputType="text" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I want to add this "debug_layout" into a centerLayout:</p>
  
  <pre><code>LinearLayout centerLayout = (LinearLayout) findViewById (R.id.center_layout);
  LinearLayout debugLayout = (LinearLayout) findViewById (R.id.debug_layout);
  centerLayout.addView(debugLayout);
  </code></pre>
  
  <p>But it encounters NULL pointer excetion at "centerLayout.addView(debugLayout);". So it seems the debug_layout is not initialized or something. Does anyone can help me?</p>