java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams

In your code you are importing import android.widget.RelativeLayout.LayoutParams; instead of android.view.ViewGroup.LayoutParams

so Delete import android.widget.RelativeLayout.LayoutParams;

and Add import android.view.ViewGroup.LayoutParams


You should make the LayoutParams object of the parent layout. Example in the layout below to set height and width of the LinearLayout you have to make the LayoutParmas of RelativeLayout not LinearLayout itself.

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".newsblog.NewsDetailsActivity"
    >

      <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>


 </RelativeLayout>

Java:

//IN ACTIVITY
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(30,30); //Parent Params
linearLayout.setLayoutParmas(params); //Child Layout


//If you want to set the params of the Relative Layout above. It seems it doesn't have any parent but it has a parent created by android framework which is a frame layout. So 
FrameLayout.LayoutParmas params=new FrameLayout.LayoutParmas(30, 30);//FrameLayout is a parentcreated by anroid frame work
relativeLayout.setLayoutParmas(params);  ////Here Relative layout is child