gpt4 book ai didi

java - Android:StaggeredGridLayoutManager 中的 ArithmeticException

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:36 29 4
gpt4 key购买 nike

我的应用程序几乎适用于 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)

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

最佳答案

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

关于java - Android:StaggeredGridLayoutManager 中的 ArithmeticException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40531197/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com