0

I have an app that has a bottom bar with three fragments. There are also a few child fragments that are being called from parent fragments. Google Play console shows several crashes due to java.lang.IllegalArgumentException. I cannot seem to replicate the error, and nothing points to my code in the logs.

Can anybody decipher what could be the problem?

Here is the error stack trace.

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)

Shown below is the launcher activity code

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;
}

When i'm inside a fragment and want to switch to another fragment, this is the code:

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();

When inside a activity and need to call an activity, I do it through the main activity :

Intent intent = new Intent(NotificationListViewActivity.this, AppMainActivity.class);
intent.putExtra("FragmentCheck", "single");
startActivity(intent);
PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
  • I have the same issue with the same log through Google Play console, I also didn't find any solution for this problem, did you solve the problem @user12345 – Muhammad Waseem Sep 18 '17 at 10:41
  • Replace getSupportFragmentManager with getChildFragmentManager when you use fragment inside a fragment – PEHLAJ Sep 18 '17 at 10:48
  • Should I use the getChildFragmentManager in the Child fragment or Parent Fragment, because I use getSupportFragmentManager in the Parent Fragment and getChildFragmentManager in the Child fragment. And if I change the Parent fragment to getChildFragmentManager. Are you sure it will solve the problem. @user12345 – Muhammad Waseem Sep 18 '17 at 11:00
  • By the it doesn't allow me to use getChildFragmentManager in the AppCompactActivity, as I am using Fragments in activity, and use other fragments in that fragment which is initialised in the Fragments and that is already with getChildFragmentManager. @user12345 – Muhammad Waseem Sep 18 '17 at 11:09
  • Use getChildFragmentManager in all types of fragments(parent/child). don't use getChildFragmentManager in activity – PEHLAJ Sep 18 '17 at 11:11
  • Already doing the same as you described @user12345 – Muhammad Waseem Sep 18 '17 at 11:12
  • Post the code in a new question and share the question link here – PEHLAJ Sep 18 '17 at 11:37

0 Answers0