title: RelativeLayout-LayoutParams cannot be cast to FrameLayout-LayoutParams
body: <p>I am trying to add images dynamically because imageview sources arechangeable also image counts are changeable.</p>
  
  <pre><code>public class MatchingGame extends AppCompatActivity {
      String TAG = "Chic";
      RelativeLayout rLayout;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          Log.d(TAG, "matchinggame OnCreate");
          super.onCreate(savedInstanceState);
          rLayout = new RelativeLayout(this);
          setContentView(rLayout);
          Log.d(TAG, "mx");
         // rLayout = (RelativeLayout) findViewById(R.id.relative_layout);
          RelativeLayout.LayoutParams rLayParams =
                  new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
          rLayParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.CENTER_IN_PARENT);
          Log.d(TAG, "mxx");
          rLayout.setLayoutParams(rLayParams);
          Log.d(TAG, "mmx");
        ImageView img1 = new ImageView(this);
         img1.setImageResource(R.drawable.ic_launcher);
          img1.setTag(1);
          Log.d(TAG, "qx");
          rLayout.addView(img1);
          Log.d(TAG, "mqqx");
          rLayParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.CENTER_IN_PARENT);
        //  rLayout.setLayoutParams(rLayParams);
          ImageView img2 = new ImageView(this);
          img1.setImageResource(R.drawable.b3_1);
          img1.setTag(2);
          rLayout.addView(img2);
  
  
      }
  
  }
  </code></pre>
  
  <p>But I got this error:</p>
  
  <pre><code>java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
  </code></pre>
  
  <p>It is about this line i guess</p>
  
  <pre><code>java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
  </code></pre>
  
  <p>I need put left center an image, andto  other side, other images so i need align parent and also size rule.</p>
  
  <p>But it gives errors.</p>
  
  <p>I have a layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:id="@+id/relative_layout"
      tools:context=".games.MatchingGame"&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Do I need this layout? Because I create layout dynamically already.  </p>
  
  <p>I tried putting this static layout also, tried making with <code>findviewbyid</code> but always same errors.</p>
  
  <p>I can see images without <code>setlayoutparams</code> method. But of course, without any rules so all images are on left corner top.</p>