gpt4 book ai didi

android - ViewPager2 异常 : java. lang.IllegalStateException:违反了设计假设

转载 作者:行者123 更新时间:2023-12-04 23:53:39 26 4
gpt4 key购买 nike

我自己无法重现此问题,但我在运行 Android 10 的小米 9 的生产环境中注意到此问题。以下是我使用的 ViewPager2RecyclerView 版本:

androidx.recyclerview:recyclerview:1.1.0 
androidx.viewpager2:viewpager2:1.0.0

这是堆栈跟踪:

Fatal Exception: java.lang.IllegalStateException: Design assumption violated.
at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:287)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:276)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:67)
at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:7556)
at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:860)
at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:107)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8601)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8559)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1643)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:675)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:527)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:803)
at android.view.View.layout(View.java:21963)
at android.view.ViewGroup.layout(ViewGroup.java:6317)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3144)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2654)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1782)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7785)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1031)
at android.view.Choreographer.doCallbacks(Choreographer.java:854)
at android.view.Choreographer.doFrame(Choreographer.java:789)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1016)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

我不确定这是从我的代码中触发的,因为堆栈跟踪不是很清楚。此外,根据 Google Issuetracker,这已在 viewpager2:1.0.0-beta03: https://issuetracker.google.com/issues/134246546 中解决。随着提交 here但就我而言并非如此。这是另一篇具有相同问题但没有太多有用答案的帖子:FragmentStateAdapter throws java.lang.IllegalStateException: Design assumption violated after configuration change .如果有人知道为什么会发生这种情况或如何解决它,那就太好了。

最佳答案

如果您覆盖 getItemId(),请确保您也覆盖 containsItem()

关于android - ViewPager2 异常 : java. lang.IllegalStateException:违反了设计假设,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59751365/

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