title: Null Pointer Exception when setting LayoutParams
body: <p>I created button in activity programmaticaly, not in xml file. Then I wanted to set it LayoutParams like in this link: <a href="https://stackoverflow.com/questions/4638832/how-to-programmatically-set-the-layout-align-parent-right-attribute-of-a-button">How to programmatically set the layout_align_parent_right attribute of a Button in Relative Layout?</a></p>
  
  <p>But when I tried to launch, I had an exception.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>RelativeLayout ll2 = new RelativeLayout(this);
      //ll2.setOrientation(LinearLayout.HORIZONTAL);
  
      ImageButton go = new ImageButton(this);
      go.setId(cursor.getInt(cursor.getColumnIndex("_id")));
      go.setClickable(true);
      go.setBackgroundResource(R.drawable.go);
      RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams)go.getLayoutParams();
      params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); // LogCat said I have Null Pointer Exception in this line
      go.setLayoutParams(params1);
      go.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i3 = new Intent(RecipesActivity.this, MedicineActivity.class);
              i3.putExtra(ShowRecipe, v.getId());
              i3.putExtra("Activity", "RecipesActivity");
              RecipesActivity.this.startActivity(i3);
          }
      });
      ll2.addView(go);
  </code></pre>
  
  <p>Why my app throws an exception? Thanks.</p>