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

ClassCastException - Adding a Footer #42

Closed
Will5 opened this issue Nov 6, 2013 · 3 comments
Closed

ClassCastException - Adding a Footer #42

Will5 opened this issue Nov 6, 2013 · 3 comments

Comments

@Will5
Copy link

Will5 commented Nov 6, 2013

In my application I have a number of fragments, most of which contain a ListView, including one with an HListView. There are two paths to the fragment with the HListView - one works without issue, and the other throws a ClassCastException. I've spent several hours trying to figure out the cause, but I can't find an answer in my code. I am not importing either of these LayoutParams, and I've made sure the ids of the layouts and layout objects are unique. Below is the log which captures the exception. Any ideas?

FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to it.sephiroth.android.library.widget.AbsHListView$LayoutParams
at it.sephiroth.android.library.widget.HListView.clearRecycledState(HListView.java:506)
at it.sephiroth.android.library.widget.HListView.resetList(HListView.java:493)
at it.sephiroth.android.library.widget.HListView.layoutChildren(HListView.java:1560)
at it.sephiroth.android.library.widget.AbsHListView.onLayout(AbsHListView.java:1676)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14016)
at android.view.ViewGroup.layout(ViewGroup.java:4647)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1879)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1700)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1005)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4243)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4777)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:998)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:765)
at dalvik.system.NativeStart.main(Native Method)

@Will5
Copy link
Author

Will5 commented Nov 8, 2013

As it turns out, it had to do with the inflater for the footer. Now my Activities/Fragments are working, but the footer is not appearing at all.

View footer = inflater.inflate(R.layout.footer_layout, null, false); // mListView, (ViewGroup) root.findViewById(R.id.footer_root)
footer.setOnClickListener(this);
mListView.addFooterView(footer, null, false);

@dvdh
Copy link

dvdh commented Nov 9, 2013

Could you try inflating the footer with the listview passed in as the parent?
View footer = inflater.inflate(R.layout.footer_layout, mListView, false);

Also make sure you add footer before setting adapter on the listview

@Will5
Copy link
Author

Will5 commented Nov 9, 2013

Thank you, I spent so much time finding the previous error that I forgot that headers and footers come before setting the adapter. Short lesson - make sure the headers/footers are set before the adapter, and make sure the inflater has the right parameters

@Will5 Will5 closed this as completed Nov 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants