{"record":{"id":"de771e1aae6c8c39","repo":"jfeinstein10/SlidingMenu","slug":"both-setbehindcontentview-must-be-called-in-oncrea","errorCode":null,"errorMessage":"Both setBehindContentView must be called in onCreate in addition to setContentView.","messagePattern":"Both setBehindContentView must be called in onCreate in addition to setContentView\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityHelper.java","lineNumber":55,"sourceCode":"\t}\n\n\t/**\n\t * Sets mSlidingMenu as a newly inflated SlidingMenu. Should be called within the activitiy's onCreate()\n\t *\n\t * @param savedInstanceState the saved instance state (unused)\n\t */\n\tpublic void onCreate(Bundle savedInstanceState) {\n\t\tmSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(R.layout.slidingmenumain, null);\n\t}\n\n\t/**\n\t * Further SlidingMenu initialization. Should be called within the activitiy's onPostCreate()\n\t *\n\t * @param savedInstanceState the saved instance state (unused)\n\t */\n\tpublic void onPostCreate(Bundle savedInstanceState) {\n\t\tif (mViewBehind == null || mViewAbove == null) {\n\t\t\tthrow new IllegalStateException(\"Both setBehindContentView must be called \" +\n\t\t\t\t\t\"in onCreate in addition to setContentView.\");\n\t\t}\n\n\t\tmOnPostCreateCalled = true;\n\n\t\tmSlidingMenu.attachToActivity(mActivity, \n\t\t\t\tmEnableSlide ? SlidingMenu.SLIDING_WINDOW : SlidingMenu.SLIDING_CONTENT);\n\t\t\n\t\tfinal boolean open;\n\t\tfinal boolean secondary;\n\t\tif (savedInstanceState != null) {\n\t\t\topen = savedInstanceState.getBoolean(\"SlidingActivityHelper.open\");\n\t\t\tsecondary = savedInstanceState.getBoolean(\"SlidingActivityHelper.secondary\");\n\t\t} else {\n\t\t\topen = false;\n\t\t\tsecondary = false;\n\t\t}\n\t\tnew Handler().post(new Runnable() {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jfeinstein10/SlidingMenu/blob/4254feca3ece9397cd501921ee733f19ea0fdad8/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityHelper.java#L37-L73","documentation":"SlidingActivityHelper.onPostCreate() requires that the host activity has already called setBehindContentView() (and setContentView()) during onCreate. If the behind/above views were never created, the helper throws IllegalStateException because the SlidingMenu cannot be assembled.","triggerScenarios":"Subclassing SlidingActivity (or using SlidingActivityHelper directly) but forgetting to call setBehindContentView() in onCreate before super.onPostCreate() runs; calling onCreate manually bypassing setup; calling onPostCreate twice.","commonSituations":"Converting a plain Activity to SlidingActivity and adding setContentView but not setBehindContentView; overriding onCreate without calling the required setup; using SlidingMenu's helper methods in a non-Sliding base class where the helper hooks were never wired.","solutions":["Call setBehindContentView(R.layout.menu_frame) in onCreate before onPostCreate","Also call setContentView(R.layout.content_frame) in onCreate","Ensure super.onCreate()/super.onPostCreate() are invoked so the helper runs at the right time","Verify onCreate is not skipped (e.g. launching the activity through an unusual path)"],"exampleFix":"// before\nprotected void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.content); }\n// after\nprotected void onCreate(Bundle b) {\n    super.onCreate(b);\n    setContentView(R.layout.content_frame);\n    setBehindContentView(R.layout.menu_frame);\n}","handlingStrategy":"validation","validationCode":"// in onCreate, before super.onPostCreate runs:\nsetContentView(R.layout.content_frame);\nsetBehindContentView(R.layout.menu_frame);","typeGuard":null,"tryCatchPattern":"try { super.onPostCreate(savedInstanceState); } catch (IllegalStateException e) { throw new IllegalStateException(\"forgot setBehindContentView in onCreate\", e); }","preventionTips":["Follow the SlidingActivity template: setContentView + setBehindContentView in onCreate","Never override onCreate/onPostCreate without calling super","Check the sample app setup when converting plain Activities"],"tags":["android","slidingmenu","lifecycle","missing-setup"],"backgroundTag":"missing-required-argument","analyzedSha":"4254feca3ece9397cd501921ee733f19ea0fdad8","analyzedAt":"2026-09-09T10:08:27.041Z","contentChangedAt":"2026-09-09T10:08:27.041Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}