Alex Rivera | Logout

java.lang.IllegalStateException: No activity

Asked 2013-04-03T09:52:37.603
10

I'm building an Android app for which I'd like my first activity to be composed of 2 tabs, one for the user's profile, and one for the friends' activity. For these tabs, I opted for a TabHost since my Sherlock Action Bar is already using list navigation to move to other activities so I can't use tab navigation from the action bar.

The app worked for a while, but now only one of my tabs works, as soon as I try to move to the second tab, I'm getting a java.lang.IllegalStateException: No activity

I added the Logcat output for this error, although I'm not sure it helps since there is no trace back to my code.

I tried replacing the TabHost with a FragmentTabHost, but the error persists...

Can anyone kindly point me to the origin/meaning of this error ? Thanks in advance !

LOGCAT :

04-03 08:19:39.380: W/dalvikvm(958): threadid=1: thread exiting with uncaught exception     (group=0x40a71930)
04-03 08:19:39.400: E/AndroidRuntime(958): FATAL EXCEPTION: main
04-03 08:19:39.400: E/AndroidRuntime(958): java.lang.IllegalStateException: No activity
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1474)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
04-03 08:19:39.400: E/AndroidRuntime(958):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:6
Edit
Report

1 Answer

24

Finally found out what this was about: the "no activity" crash was due to the fact that I was using a wrong FragmentManager to nest Fragments.

For nested fragments, the only valid FragmentManager is the one obtained in the containing Fragment, by calling getChildFragmentManager().

answered 2013-06-16T08:15:33.583

Your Answer