Reputation: 32207
Preface
I'm maintaining an app that I inherited from another team
Scenario
I understand ClassCastException
but for the life of me I cannot find where this error is occurring in the code.
01-27 14:47:15.839 13272-13272/com.xx.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xx.android, PID: 13272
java.lang.ClassCastException: com.xx.viewmodels.components.AutoValue_SpecialViewModel cannot be cast to com.xx.viewmodels.components.NormalViewModel
at com.xx.android.viewholders.NormalViewHolder.bind(NormalViewHolder.java:27)
at com.xx.android.BaseAdapter.onBindViewHolder(BaseAdapter.java:39)
at com.xx.android.componentfeed.ComponentFeedAdapter.onBindViewHolder(ComponentFeedAdapter.java:123)
at com.xx.android.componentfeed.ComponentFeedAdapter.onBindViewHolder(ComponentFeedAdapter.java:79)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6541)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5484)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5750)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5585)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2231)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1558)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1518)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:610)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3719)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3436)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3988)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:611)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1731)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1496)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:874)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1171)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:856)
at android.support.design.widget.ViewOffsetBehavior.layoutChild(ViewOffsetBehavior.java:63)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:136)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:874)
at andro
(I'm not sure why the output cutoff at that point)
NormalViewHolder.java
line 27
public class NormalViewHolder extends ComponentViewHolder<NormalViewModel> {
lines 55-64
public NormalViewHolder(final View itemView, final RecyclerView.RecycledViewPool relatedItemsViewPool) {
super(itemView);
Dagger.getInstance(itemView.getContext()).inject(this);
ButterKnife.bind(this, itemView);
adapter = new NormalRelatedItemsAdapter();
recyclerView.setRecycledViewPool(relatedItemsViewPool);
recyclerView.setAdapter(adapter);
recyclerView.setNestedScrollingEnabled(false);
}
The app stops abruptly even with the settings found in my screenshot below. I've set breakpoints all around bind
and onBindViewHolder
and followed them as far as they go with no avail. How can I go about tracking down this issue? I was thinking I could move around in a breakpoint to put things together but I'm not having any luck.. Suggestions?
Extra
In researching the issue I've adjusted my breakpoint settings to the following with no success:
Upvotes: 1
Views: 394
Reputation: 32207
This was an impossible situation to debug.
This app was written to leverage dagger modules. In the app there was a line that referenced an incompatible class but in a file that was never even mentioned in the stack trace - making my methods of debugging rather useless.
Ultimately I had to go through line by line, manually inspecting every situation. Good old fashioned elbow grease.
Upvotes: 1