gpt4 book ai didi

android - 恢复 Activity 时 FragmentManager 出现 IndexOutOfBoundsException

转载 作者:搜寻专家 更新时间:2023-11-01 08:28:55 24 4
gpt4 key购买 nike

问题是什么:我有一个主要 Activity ,在加载时总共添加了 7 个 fragment :2 个抽屉导航 fragment 、1 个 viewPager 主 fragment 和 4 个 viewpager 子 fragment 。

只要有需要,就会添加新的 fragment 。所以在问题发生之前又添加了两个 fragment 。添加的最后一个 fragment 打开了另一个 Activity “cardActivity”。当此 cardActivity 在以编程方式按下后退时完成,然后发生以下错误:

02-14 11:06:29.759 16930-16930/com.myapp.app E/UncaughtException: java.lang.RuntimeException: Unable to resume activity {com.myapp.app/com.myapp.app.Activities.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2800)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2829)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1584)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2842)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:175)
at android.app.Activity.performResume(Activity.java:5367)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2829) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5118) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 
at dalvik.system.NativeStart.main(Native Method) 
02-14 11:06:30.062 16930-16930/com.myapp.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.app, PID: 16930
java.lang.RuntimeException: Unable to resume activity {com.myapp.app/com.myapp.app.Activities.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2800)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2829)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1584)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2842)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:175)
at android.app.Activity.performResume(Activity.java:5367)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2829) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5118) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 
at dalvik.system.NativeStart.main(Native Method) 

这个错误是随机发生的,有时会发生有时不会。

到目前为止我尝试了什么:我尝试重现此问题,并检查是否在两者之间删除了一些 fragment ,但没有删除任何 fragment 。

我也在此处发现了同样的问题:https://code.google.com/p/android/issues/detail?id=231430但是那里也没有解决方案。在 MainActivity 的 OnResume() 中也没有做任何事情,它只是被覆盖了,没有别的:

    @Override
protected void onResume() {
super.onResume();
}

谁能告诉我这个问题的可能原因是什么?

最佳答案

这不是解决方案,而是朝着正确方向迈出的一步:)

我想这就是问题 - https://code.google.com/p/android/issues/detail?id=231430

有人已经报告了此事,目前正在跟踪中。我认为您可以添加您的 2 美分,并帮助您输入有关此问题何时发生的信息,如果可能的话,请提供您的应用程序以供采样。

关于android - 恢复 Activity 时 FragmentManager 出现 IndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218899/

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