1

我的应用程序适用于几乎 android 版本。但是,在 Crashlytics 和某些设备中,我遇到了这个崩溃:“java.lang.ArithmeticException:除以零”。它几乎(如果不是总是)在 Android 4.x 中。

我在 RecyclerView (SuperRecyclerView) 中有一个 StaggeredGridLayoutManager。

堆栈跟踪:

Fatal Exception: java.lang.ArithmeticException: divide by zero
   at android.support.v7.widget.StaggeredGridLayoutManager.updateMeasureSpecs(StaggeredGridLayoutManager.java:922)
   at android.support.v7.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:665)
   at android.support.v7.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:600)
   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3374)
   at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3183)
   at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3627)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:630)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1142)
   at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:836)
   at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:850)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1799)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
   at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
   at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:14102)
   at android.view.ViewGroup.layout(ViewGroup.java:4662)
   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2019)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1840)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1135)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4579)
   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:4935)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
   at dalvik.system.NativeStart.main(NativeStart.java)

我不知道解决这个问题需要什么样的信息,所以请问我你需要什么,以便我更新问题。

4

1 回答 1

0

也看到了,但在 Android 5 和 7 上也看到了。我检查了代码,显然当 mSpanCount 为 0 时它会崩溃。与GridLayoutManager,不同StaggeredGridLayoutManager的是,setSpanCount它不会检查它是否为 1 或更大,只是稍后崩溃。就我而言,跨度计数为 0,因为我使它取决于屏幕尺寸,在极少数情况下似乎为 0。

于 2017-06-21T04:18:23.243 回答