"requestFeature () must be called before adding the contents of the" master part template "

I started a new application with a master part template.

When I try to use the application on my tablet using a two-panel layout, it crashes with an exception in the title when I change the orientation of the tablet. This only happens if a part fragment has content.

The failure is on the line super.onCreate, I don’t even call requestFeature, so it’s not even my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_list);

    if (findViewById(R.id.item_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;

        // In two-pane mode, list items should be given the
        // 'activated' state when touched.
        ((ItemListFragment) getSupportFragmentManager().findFragmentById(
                R.id.item_list)).setActivateOnItemClick(true);
    }

 }

Stack trace:

 12-14 23:18:44.716: E/AndroidRuntime(32065): FATAL EXCEPTION: main
 12-14 23:18:44.716: E/AndroidRuntime(32065): Process: com.manor.barcam, PID: 32065
 12-14 23:18:44.716: E/AndroidRuntime(32065): java.lang.RuntimeException: Unable to  start activity ComponentInfo{com.manor.barcam/com.manor.barcam.ItemListActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.access$900(ActivityThread.java:135)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at  android.os.Handler.dispatchMessage(Handler.java:102)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.os.Looper.loop(Looper.java:136)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.main(ActivityThread.java:5017)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at java.lang.reflect.Method.invokeNative(Native Method)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at java.lang.reflect.Method.invoke(Method.java:515)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at dalvik.system.NativeStart.main(Native Method)
 12-14 23:18:44.716: E/AndroidRuntime(32065): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:249)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.Activity.requestWindowFeature(Activity.java:3298)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:63)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at com.manor.barcam.ItemListActivity.onCreate(ItemListActivity.java:54)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.Activity.performCreate(Activity.java:5231)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
 12-14 23:18:44.716: E/AndroidRuntime(32065):   ... 12 more

How can I solve it?

Thanks.

+4
source share
4 answers

, , . ActionBarActivityDelegateICS.java appomppat, requestWindowFeature() super.onCreate:

    super.onCreate(savedInstanceState);

    if (mHasActionBar) {
        // If action bar is requested by inheriting from the appcompat theme,
        // the system will not know about that. So explicitly request for an action bar.
        mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
    }
    if (mOverlayActionBar) {
        mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY);
    }

, appcompat git , super.onCreate() .requestWindowFeature(), . Google

+4

. .

, android OS .

, super.onCreate(savedInstanceState);

, savedInstanceState null. , . super.onCreate(null), savedInstanceState null.

  /*
            * This may be the wrong workaround!!!
            * It demands more research..
            * But for now, if it solves the problem, then it is a solution :D
            * */
        if(savedInstanceState!=null){
            super.onCreate(null);
        } else {
            super.onCreate(savedInstanceState);
        }

.

+3

. getActivity().getActionBar() onCreate(). ContentView , .

onViewCreated()

+2

getSupportActionBar(); getActionBar();

+1

All Articles