1

The Stacktrace I got in crashlytics fabric is as follows,

Fatal Exception: java.lang.IllegalStateException: No activity
   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053)
   at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1862)
   at android.app.Fragment.performActivityCreated(Fragment.java:1724)
   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1071)
   at android.app.BackStackRecord.run(BackStackRecord.java:684)
   at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1456)
   at android.app.FragmentManagerImpl$1.run(FragmentManager.java:444)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5398)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
   at dalvik.system.NativeStart.main(NativeStart.java)
Show all 74 Threads

I am not finding it helpful in any way. Can anybody tell me how can I trace it and how to find which activity is causing problem and what may be the problem?

Ritzor
  • 665
  • 7
  • 26
  • 1
    Well, not enough information to comment, you just displayed an error stack trace... what Fragment is involved with this error, when does it occur? Are you pressing the back button by any chance when this occurs? – Robert Ruxandrescu Sep 11 '17 at 13:42
  • https://stackoverflow.com/questions/34207353/illegalstateexception-no-activity-fragmentmanager-java https://stackoverflow.com/questions/15784155/java-lang-illegalstateexception-no-activity https://stackoverflow.com/questions/14929907/causing-a-java-illegalstateexception-error-no-activity-only-when-navigating-to You gotta try a little bit – JJF Sep 11 '17 at 13:43
  • This stacktrace I got from crashlytics, and its all what crashlytics provided, I have no Idea where it caused as the project is pretty big – Ritzor Sep 11 '17 at 13:48

1 Answers1

2

You are using wrong FragmentManager to nest the fragments. You should use fragmentManager instance returned by

getChildFragmentManager();  

instead of using

getSupportFragmentManager();

You can get more information about nested fragments here : https://developer.android.com/about/versions/android-4.2.html#NestedFragments

You can embed fragments inside fragments. This is useful for a variety of situations in which you want to place dynamic and re-usable UI components into a UI component that is itself dynamic and re-usable. You can insert fragments into each fragment page.

To nest a fragment, simply call getChildFragmentManager() on the Fragment in which you want to add a fragment. This returns a FragmentManager that you can use like you normally do from the top-level activity to create fragment transactions. For example, here’s some code that adds a fragment from within an existing Fragment class:

Fragment videoFragment = new VideoPlayerFragment();
FragmentTransaction transaction = 
      getChildFragmentManager().beginTransaction();
    transaction.add(R.id.video_fragment, videoFragment).commit();

From within a nested fragment, you can get a reference to the parent fragment by calling getParentFragment().

Shriyansh Gautam
  • 1,084
  • 1
  • 7
  • 13