gpt4 book ai didi

android - LifecycleRegistry 的 popParentState 出现 ArrayIndexOutOfBoundsException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:33 26 4
gpt4 key购买 nike

我一直面临着将架构组件添加到 fragment 时发生的这种奇怪的崩溃崩溃随机发生我无法用直接场景重现它我有一个控制 5 个 fragment 的 navigation bottom bar其中一个 fragment 有一个实现 LifecycleObserver 的演示者崩溃日志:

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
at java.util.ArrayList.remove(ArrayList.java:405)
at android.arch.lifecycle.LifecycleRegistry.popParentState(LifecycleRegistry.java:194)
at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:293)
at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332)
at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137)
at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123)
at android.support.v4.app.Fragment.performStart(Fragment.java:2380)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

替换该 fragment 后发生崩溃我的代码的代码跟踪从这里开始

getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.replace(R.id.flMain, fragment, tabModel.getName())
.addToBackStack(BACK_STACK_ROOT_TAG)
.commitAllowingStateLoss();

这里可能存在哪些问题?

最佳答案

你必须确保你的操作是在UI线程中

getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.replace(R.id.flMain, fragment, tabModel.getName())
.addToBackStack(BACK_STACK_ROOT_TAG)
.commitAllowingStateLoss();

关于android - LifecycleRegistry 的 popParentState 出现 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51817682/

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