0

Using nested fragments via XML or programmatically works great on a 4.2/4.3 device.

When 2.3 tries to use nested fragments and has AppCompat's action bar, it seems like the nested fragments want access to the action bar, but cannot find it... because they're nested in a fragment and should not have one.

I know there are some gotchas when using AppCompat like: AppCompat, fragments, & 2.3, and am hoping this can be solved just as easily.

XML layout:

<fragment
   android:id="@+id/my_fragment"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:name="my.package.MyFragment"
   tools:layout="@layout/my_layout" />

Manifest.xml:

<application
   ...
  android:theme="@style/Theme.AppCompat.Light">

Stack trace:

E/AndroidRuntime( 6487): java.lang.RuntimeException: Unable to start activity ComponentInfo{your.package.here/your.package.here.SomeActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f080014 (your.package.here:id/action_bar_activity_content) for fragment ProfileFragment{406160e0 #0 id=0x7f080014 SomeFragment}

E/AndroidRuntime( 6487):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
E/AndroidRuntime( 6487):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
E/AndroidRuntime( 6487):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 6487):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
E/AndroidRuntime( 6487):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6487):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 6487):    at android.app.ActivityThread.main(ActivityThread.java:3691)
E/AndroidRuntime( 6487):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 6487):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 6487):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
E/AndroidRuntime( 6487):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
E/AndroidRuntime( 6487):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 6487): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f080014 (your.package.here:id/action_bar_activity_content) for fragment SomeFragment{406160e0 #0 id=0x7f080014 SomeFragment}
E/AndroidRuntime( 6487):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
E/AndroidRuntime( 6487):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
E/AndroidRuntime( 6487):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
E/AndroidRuntime( 6487):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
E/AndroidRuntime( 6487):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
E/AndroidRuntime( 6487):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
E/AndroidRuntime( 6487):    at android.app.Activity.performStart(Activity.java:3833)
E/AndroidRuntime( 6487):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
E/AndroidRuntime( 6487):    ... 11 more

How can I fix this while still using nested fragments and the AppCompat action bar?

Community
  • 1
  • 1
Shellum
  • 3,159
  • 2
  • 21
  • 26
  • Did you double check not to use the same Ids in inner and outer fragments ? – Snicolas Aug 16 '13 at 22:43
  • The outer Fragment is added programmatically in the Activity with a tag and no id. The inner Fragment does have an id. – Shellum Aug 16 '13 at 22:51
  • Are you sure your fragment (outer) has been removed properly or is not duplicated ? Can you show the code to add your fragment ? You should check if findFragmentByTag returns null before (re)adding it. – Snicolas Aug 16 '13 at 22:56
  • The issue is that is never gets added in the first place. It isn't a re-add problem, it's a add once for the first time problem. – Shellum Aug 19 '13 at 14:34

0 Answers0