sergejsha / pinned-section-listview

Easy to use ListView with pinned sections for Android.
2.59k stars 808 forks source link

java.lang.ClassCastException #64

Closed josluimg closed 8 years ago

josluimg commented 9 years ago

My app got some java.lang.ClassCastException on some devices. I don't altered the code of the lib. Errors from Google Play:

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at PinnedSectionListView.createPinnedShadow(PinnedSectionListView.java:201)
at  PinnedSectionListView.ensureShadowForPosition(PinnedSectionListView.java:251)
at  PinnedSectionListView$1.onScroll(PinnedSectionListView.java:116)

Errors on: Android 4.0.3 - 4.0.4, Xperia Tipo (ST21i), Xperia U (ST25i)

gianpaolodn commented 9 years ago

I'm facing the same error on: Android 4.0.3 - 4.0.4, HUAWEI U9508 (hwu9508)

did you find a solution or a workaround to solve this?

gianpaolodn commented 9 years ago

Ok, i found how to avoid (line 200) this:

if(generateDefaultLayoutParams() instanceof LayoutParams) {
     layoutParams = (LayoutParams) generateDefaultLayoutParams();
}
else{
     layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,AbsListView.LayoutParams.WRAP_CONTENT, 0);
}
yv-code commented 9 years ago

I got same error on Android 4.0.4, SAMSUNG GT-S7562i. And @gianpaolodn solution worked perfectly, thank you!

gohilronak commented 8 years ago

I got same error on Android 2.2 emulator Because pinnedView.getLayoutParams(), generateDefaultLayoutParams() return ViewGroup.LayoutParamsand not LayoutParams, we need to set type of layoutParams to ViewGroup.LayoutParams

ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) pinnedView.getLayoutParams();
if (layoutParams == null) {
        layoutParams = (ViewGroup.LayoutParams) generateDefaultLayoutParams();
        pinnedView.setLayoutParams(layoutParams);
}

Changes are done here.