Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot be cast in StickyHeaderHelper #594

Closed
volser opened this issue Apr 17, 2018 · 5 comments
Closed

cannot be cast in StickyHeaderHelper #594

volser opened this issue Apr 17, 2018 · 5 comments

Comments

@volser
Copy link

volser commented Apr 17, 2018

I saw this issue #299
looks like similar, but marked as resolved.
I use last version 5.0.3

java.lang.ClassCastException: com.test.CategoryTableModelItem$ExpandableHeaderViewHolder cannot be cast to com.test.SubcategoryTableModelItem$ExpandableHeaderViewHolder
at com.test.SubcategoryTableModelItem.bindViewHolder(SubcategoryTableModelItem.java:32)
at eu.davidea.flexibleadapter.FlexibleAdapter.onBindViewHolder(FlexibleAdapter.java:1769)
at eu.davidea.flexibleadapter.FlexibleAdapter.onBindViewHolder(FlexibleAdapter.java:1746)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateHeader(StickyHeaderHelper.java:168)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateOrClearHeader(StickyHeaderHelper.java:139)
at eu.davidea.flexibleadapter.FlexibleAdapter$AdapterDataObserver$1.run(FlexibleAdapter.java:5282)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

@volser
Copy link
Author

volser commented Apr 17, 2018

very hard to reproduce (was able 2 times)

@davideas
Copy link
Owner

@volser, I might have an idea. The stacktrace says it comes from an Adapter modification with AdatperDataObserver callback from RV.
The following code has been introduced to give time to the LayoutManager to finish the layout and so having the positions synced.

// #320 - To include adapter changes just notified we need a new layout pass:
// We must give time to LayoutManager otherwise ... will return wrong position!
mRecyclerView.postDelayed(new Runnable() {
    @Override
    public void run() {
        if (areHeadersSticky()) mStickyHeaderHelper.updateOrClearHeader(true);
    }
}, 50L);

That 50ms might be too low, it might explain why it's hard to reproduce.
I can try to build a SNAPSHOT version increasing that value, so you can try and tell me.
I can eventually check if the object is of the same type and allow the binding.

@davideas
Copy link
Owner

Please try with 5.0.4-SNAPSHOT, this has 100ms delay.
I've also put an if-else when itemView types don't match, you should see an error log with the Holders class names (I expect to be different in that case).

allprojects {
    repositories {
        // For SNAPSHOT
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}
dependencies {
    implementation ('eu.davidea:flexible-adapter:5.0.4-SNAPSHOT') {
        changing = true;
    }
}

@davideas
Copy link
Owner

@volser waiting your tests. Thanks :-)

@volser
Copy link
Author

volser commented Apr 19, 2018

@davideas thank you! I will test soon, but it will take some time, cuz it's not so easy to reproduce )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants