[英]java.lang.IllegalStateException crash reports from Google Play Console
I have a trouble with my Android app. 我的Android应用出现问题。 Some devices which use Android 7.1 or 8.0 often report IllegatStateException crash.
使用Android 7.1或8.0的某些设备通常会报告IllegatStateException崩溃。 I have searched on Google and tried to fix it many times but no use.
我在Google上进行了搜索,并试图对其进行多次修复,但没有用。 I cannot figure out what causes this crash.
我不知道是什么原因导致了崩溃。 So please help me if you have time.
如果有时间请帮助我。 Here is a full report:
这是一份完整的报告:
java.lang.IllegalStateException:
at android.support.v4.app.FragmentManagerImpl.addFragment (FragmentManagerImpl.java:60)
at android.support.v4.app.BackStackRecord.executeOps (BackStackRecord.java:137)
at android.support.v4.app.FragmentManagerImpl.executeOps (FragmentManagerImpl.java:38)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether (FragmentManagerImpl.java:112)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManagerImpl.java:89)
at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManagerImpl.java:21)
at android.support.v4.app.FragmentManagerImpl$1.run (FragmentManagerImpl.java:2)
at android.os.Handler.handleCallback (Handler.java:869)
at android.os.Handler.dispatchMessage (Handler.java:101)
at android.os.Looper.loop (Looper.java:206)
at android.app.ActivityThread.main (ActivityThread.java:6733)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:845)
I have a main activity contains a FrameLayout. 我有一个主要活动包含一个FrameLayout。 I use this FrameLayout to display 5 different fragments by using:
我使用以下FrameLayout通过以下方式显示5个不同的片段:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
switch (button) {
case 1:
ft.replace(R.id.mainframe, fragment1, FRAGMENT1_TAG);
break;
case 2:
ft.replace(R.id.mainframe, fragment2, FRAGMENT2_TAG);
break;
case 4:
Fragment fragment4 = new Fragment();
ft.replace(R.id.mainframe, fragment4, FRAGMENT4_TAG);
break;
}
ft.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
ft.commit();
Some fragments must be saved to restore later (fragment 1 -> 3), some must be refreshed (create new instance) (fragment 4 -> 5). 必须保存一些片段以供以后还原(片段1-> 3),一些片段必须刷新(创建新实例)(片段4-> 5)。 Moreover, on fragment 4 and 5, there are a viewpager and an array of button to move between pages for each.
此外,在片段4和5上,有一个viewpager和一个按钮数组,每个按钮都在页面之间移动。 The code of viewpagers:
Viewpagers的代码:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager(), new Fragment[] {
new Page1(),
new Page2()
}));
}
private void onButtonTap(Button btn) {
switch (btn.getId()) {
case R.id.button1:
viewPager.setCurrentItem(0, true);
break;
case R.id.button2:
viewPager.setCurrentItem(1, true);
break;
}
}
I also define 2 classes derive from Dialog and use Toast. 我还定义了两个从Dialog派生的类,并使用Toast。 I cannot reproduce on simulators or my devices.
我无法在模拟器或设备上复制。 It just happens on a few devices.
它仅在少数设备上发生。 Is there anything wrong with my code?
我的代码有什么问题吗? Please help me.
请帮我。 This crash stays for a long time, I need to get rid of it.
崩溃持续了很长时间,我需要摆脱它。 I'm looking forward to hearing from you.
我期待着您的回音。 Thank you very much.
非常感谢你。
Long 长
Edit 1: Here is where I call ft.replace on fragment 1 编辑1:这是我在片段1上调用ft.replace的地方
@Override
protected void onResume() {
// Check server connection to go back to the first fragment
if (!ConnectivityReceiver.getInstance().isServerConnected()) {
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.main_frame);
if (currentFragment != null &&
(FRAGMENT_4_TAG.equals(currentFragment.getTag()) || FRAGMENT_5_TAG.equals(currentFragment.getTag())) && isActive()) {
.....
ft.replace(fragment1);
}
}
}
According to the source code, the addFragment
method throws that exception with the message "Fragment already added"
if you attempt to add a Fragment
that is already a member of the manager. 根据源代码,如果您尝试添加已经是管理器成员的
Fragment
,则addFragment
方法将引发该异常并显示消息"Fragment already added"
。
Now, the version of the FragmentManagerImpl
source code that I can see looks rather different to the stack trace, so this is a bit of a guess. 现在,我可以看到的
FragmentManagerImpl
源代码版本看起来与堆栈跟踪完全不同,因此这有点猜测。 But I suspect that the problem is that you may be calling ft.replace
on fragment2
or fragment1
when they are already part of the layout. 但是我怀疑问题是,当
fragment2
或fragment1
已经是布局的一部分时,您可能正在调用ft.replace
。 Under certain circumstances .... 在某些情况下 ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.