title: adding a RelativeLayout to a LinearLayout dynamically
body: <p>I am trying to get a RelativeLayout created dynamically (with views added dynamically to it) and add it to a dynamic created LinearLayout. Follows the code:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Log.d("TAG", "ON CREATE");
  
      LinearLayout mainLO = (LinearLayout) findViewById(R.id.linearLayout);
      Log.d("TAG", "LINEAR LAYOUT CREATED");
  
      setContentView(R.layout.activity_main);
      Log.d("TAG", "CONTENT SET");
  
      relLO = new RelativeLayout(this);
      RelativeLayout.LayoutParams lpMatchParent = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.MATCH_PARENT,
              RelativeLayout.LayoutParams.WRAP_CONTENT);
      lpMatchParent.addRule(RelativeLayout.ALIGN_PARENT_TOP);
      relLO.setBackgroundColor(0xBBBBBBBB);
      relLO.setId(10);
      Log.d("TAG", "relLO CREATED");
  
      btn1 = new Button(this);
      btn1.setText("Btn1");
      btn1.setId(1);
      btn1.setOnClickListener(this);
      btn1Created = true;
      Log.d("TAG", "BUTTON ONE CREATED");
  
      btn2 = new Button(this);
      btn2.setText("Btn2");
      btn2.setId(2);
      btn2.setOnClickListener(this);
      btn2Created = true;
      Log.d("TAG", "BUTTON TWO CREATED");
  
      btn3 = new Button(this);
      btn3.setText("Btn3");
      btn3.setId(3);
      btn3.setOnClickListener(this);
      btn3Created = true;
      Log.d("TAG", "BUTTON THREE CREATED");
  
      lpWrapContent = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.WRAP_CONTENT,
              RelativeLayout.LayoutParams.WRAP_CONTENT);
      lpWrapContent.addRule(RelativeLayout.CENTER_HORIZONTAL);
      lpWrapContent.setMargins(10, 2, 10, 2);
      Log.d("TAG", "lpWrapContent CREATED");
  
      lpWrapContentRight = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.WRAP_CONTENT,
              RelativeLayout.LayoutParams.WRAP_CONTENT);
      lpWrapContentRight.addRule(RelativeLayout.RIGHT_OF, btn1.getId());
      lpWrapContentRight.setMargins(10, 2, 10, 2);
      Log.d("TAG", "lpWrapContentRight CREATED");
  
      lpWrapContentLeft = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.WRAP_CONTENT,
              RelativeLayout.LayoutParams.WRAP_CONTENT);
      lpWrapContentLeft.addRule(RelativeLayout.LEFT_OF, btn1.getId());
      lpWrapContentLeft.setMargins(10, 2, 10, 2);
      Log.d("TAG", "lpWrapContentLeft CREATED");
  
      relLO.addView(btn1, lpWrapContent);
      relLO.addView(btn2, lpWrapContentRight);
      relLO.addView(btn3, lpWrapContentLeft);
      Log.d("TAG", "VIEWS ADDED");
  
      mainLO.addView(relLO, lpMatchParent);
      Log.d("TAG", "relLO ADDED TO LINEAR LAYOUT");
  }
  </code></pre>
  
  <p>I get a NULL pointer exception on the last line <code>mainLO.addView(relLO, lpMatchParent);</code> , any idea why?</p>