Class Cast Exception - Expandable Extension
About this issue
- Crash - Fatal Exception: java.lang.ClassCastException - Child Expandable cannot be cast to Parent Expandable on FastAdapter - onClickListener
- Not Always , but if you open and close multiple times and scroll up and down and the expand, it crashes.
Details
- [ ] fastadapter:3.3.1@aar
- [ ] fastadapter-extensions-expandable:3.3.1
- [ ] build:gradle:3.2.1
- [ ] 3.2.1
Checklist
- [ Y ] Searched for similar issues
- [ Y ] Checked out the sample application
- [ Y ] Read the README
- [ Y ] Checked out the CHANGELOG
- [ Y ] Checked out the MIGRATION GUIDE
@sid-dob please make sure your adapter type definition is a super type of all your items.
If you have the following
SuperType
- ChildTypeA extends SuperType
- ChildTypeB extends SuperType
Then the following applies
FastAdapter
FastAdapter
FastAdapter
Here , do you mean ->
ChildTypeA = ExpandableParent ChildTypeB = Expandablee ( i.e. the item that shows up after expansion )
Is this complex ? or am I missing on something ? Here are the definitions :
@Suppress("FINITE_BOUNDS_VIOLATION_IN_JAVA")
class ProductDetailExpandableItem<Parent, SubItem>(
val productDetailState: ProductDetailExpandableItemState
) : AbstractExpandableItem<ProductDetailExpandableItem<Parent, SubItem>,
ProductDetailExpandableItemViewHolder, SubItem>()
where Parent : IItem<*, *>,
Parent : IExpandable<*, *>,
SubItem : IItem<*, *>,
SubItem : ISubItem<*, *>
Expandee
@Suppress("FINITE_BOUNDS_VIOLATION_IN_JAVA")
class ProductDetailExpandableDetailsItem<Parent>(
val data: String?, val viewType: Int
) : AbstractExpandableItem<Parent, FastAdapter.ViewHolder<*>, ProductDetailExpandableDetailsItem<Parent>>()
where Parent : IItem<*, *>,
Parent : IExpandable<*, *>,
Parent : IClickable<*>,
Parent : ISubItem<*, *>
What type definition does your adapter have?
FastAdapter<IItem>
FastAdapter<ProductDetailExpandableItem>
FastAdapter<AbstractExpandableItem>
The first super type of your items is the AbstractExpandableItem so you can do FastAdapter< AbstractExpandableItem> alternative IItem will work always
I am using this :
val fastItemAdapter = FastItemAdapter<ProductDetailExpandableItem<*, *>>()
However I think I understand the problem, this should solve it.
val fastItemAdapter = FastItemAdapter<IItem<*, *>>()
for others after that you we will have to instance check and cast in onClick
fastItemAdapter.withOnClickListener { v, adapter, item, position ->
// check instance of here and cast and perform actions
}
Yes , this setup is working.