I get this exception when I try to inflate
07-22 19:15:39.903: ERROR/AndroidRuntime(3810): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
I have a base class:
public class UIBase extends RelativeLayout {}
And a more specific class:
public class Countdown extends UIBase {}
Then I try to inflate and it exceptions:
UIBase newView = (UIBase) inflater.inflate(layoutId, parent, true);
Here's the XML file:
<?xml version="1.0" encoding="utf-8"?>
<com.Countdown xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/countdown"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/countdownText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="0" />
</com.Countdown>
Does anyone know what I'm doing wrong?
As per the documentation, inflate() returns "the root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root; otherwise it is the root of the inflated XML file."
Since you passed in true, the return value is "parent", which is apparently not derived from UIBase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With