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
Android.Database.Cursorindexoutofboundsexception: Index 0 Requested, with a Size of 0
Error Message:This Android Sdk Requires Android Developer Toolkit Version 22.6.1 or Above
Pathpattern to Match File Extension Does Not Work If a Period Exists Elsewhere in the File Name
Run Code When Android App Is Closed/Sent to Background
Calculate Text Size According to Width of Text Area
Where to Find Info on Android's "Service Call" Shell Command
Flutter Projects & Android X Migration Issues
Detect Touch Event on a View When Dragged Over from Other View
Start Activity Inside Onreceive Broadcastreceiver
Android: Retrieve Contact Name from Phone Number
How to Retrieve the Logged in Google Account on Android Phones
Get List of Installed Android Applications
Appcompatactivity.Oncreate Can Only Be Called from Within the Same Library Group
How to Use the Same Keystore File to Sign Two Different Applications
Textview with Different Textsize
How to Set the Divider Between Tabs in Tablayout of Design Support Library