Android Studio - 如何调试这种情况?

时间:2018-01-27 20:24:21

标签: android-studio debugging breakpoints

前言

我正在维护一个我从其他团队继承的应用程序

方案

我理解ClassCastException但是对于我的生活,我无法找到代码中出现此错误的位置。

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

(我不确定为什么在那时输出截止值)

NormalViewHolder.java

第27行

public class NormalViewHolder extends ComponentViewHolder<NormalViewModel> {

第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);
}

问题

即使使用下面的屏幕截图中的设置,应用也会突然停止。我在bindonBindViewHolder周围设置了断点,并且只要它们无效就跟着它们。我怎样才能追查这个问题?我以为我可以在一个断点处移动来把事情放在一起但是我没有运气..建议?

附加

在研究这个问题时,我已将断点设置调整为以下内容但没有成功:

android studio break points

1 个答案:

答案 0 :(得分:0)

这是一个无法调试的情况。

这个应用程序是利用dagger模块编写的,有一行引用了错误的类,但在一个文件中,甚至从未在堆栈跟踪中提到过。

最终我必须逐行检查,手动检查每种情况。小时工作的小时数。