Java.Lang.Classcastexception: Android.View.Viewgroup$Layoutparams Cannot Be Cast to Android.Widget.Gallery$Layoutparams

android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

dialogTitle.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

Here you're replacing existing layout params of correct type AbsListView.LayoutParams with more generic ViewGroup.LayoutParams. Layout params type is that of the parent container of the view.

If you need to modify existing layout params, access them with getLayoutParams(), modify it, and call requestLayout() to notify that the layout has changed.

Example. Instead of

fooView.setLayoutParams(new LayoutParams(123, 456));

do

LayoutParams lp = fooView.getLayoutParams();
lp.width = 123;
lp.height = 456;
fooView.requestLayout();

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

ClassCastException: android.widget.LinearLayout$LayoutParams

Use android.widget.AbsListView.LayoutParams instead of the android.widget.LinearLayout.LayoutParams in your imports.

A ClassCastException stacktrace is pretty descriptive...

android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

So it turns out that on API < 17 FrameLayout can't be cast correctly to AbsListView params.

What I did was set AbsListView LayoutParams instead of FrameLayout params:

    setLayoutParams(new AbsListView.LayoutParams(100,100));


Related Topics



Leave a reply



Submit