我有一个带有三个片段的底栏的应用程序。还有一些从父片段调用的子片段。 Google Play控制台显示由于java.lang.IllegalArgumentException
导致的多次崩溃。我似乎无法复制错误,并且没有任何内容指向我在日志中的代码。
有人可以解读可能出现的问题吗?
这是错误堆栈跟踪。
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3190)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3300)
at android.app.ActivityThread.access$1000 (ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1705)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:145)
at android.app.ActivityThread.main (ActivityThread.java:6946)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
Caused by: java.lang.IllegalArgumentException:
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1293)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1595)
at android.support.v4.app.BackStackRecord.executeOps (BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.executeOps (FragmentManager.java:2363)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether (FragmentManager.java:2149)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps (FragmentManager.java:2103)
at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:2013)
at android.support.v4.app.FragmentController.execPendingActions (FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1264)
at android.app.Activity.performStart (Activity.java:6613)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3153)
下面显示的是启动器活动代码
public void onMenuItemSelected(int itemId) {
Fragment fragment;
switch (itemId) {
case R.id.home:
fragment = new HomeFragment();
if (fragment != null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment).commit();
}else {
}
break;
case R.id.profile:
fragment = new ProfileFragment();
if (fragment != null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment).commit();
}else {
}
break;
case R.id.account:
fragment = new AccountMainFragment();
if (fragment != null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment).commit();
}else {
//Log.e("MainActivity", "Error in creating fragment");
}
break;
}
当我在片段内部并想要切换到另一个片段时,这就是代码:
SingleProductFragment fragment = new SingleProductFragment();
fragment.setArguments(bundle);
FragmentManager fragmentManager = (((AppCompatActivity) context).getSupportFragmentManager()); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.addToBackStack("single");
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.commit();
当进入活动并需要调用活动时,我会通过主要活动来完成:
Intent intent = new Intent(NotificationListViewActivity.this, AppMainActivity.class);
intent.putExtra("FragmentCheck", "single");
startActivity(intent);