{"record":{"id":"d88bece9a9490775","repo":"jfeinstein10/SlidingMenu","slug":"enableslidingactionbar-must-be-called-in-oncreate","errorCode":null,"errorMessage":"enableSlidingActionBar must be called in onCreate.","messagePattern":"enableSlidingActionBar must be called in onCreate\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityHelper.java","lineNumber":97,"sourceCode":"\t\t\t\t\t\tmSlidingMenu.showMenu(false);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tmSlidingMenu.showContent(false);\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Controls whether the ActionBar slides along with the above view when the menu is opened,\n\t * or if it stays in place.\n\t *\n\t * @param slidingActionBarEnabled True if you want the ActionBar to slide along with the SlidingMenu,\n\t * false if you want the ActionBar to stay in place\n\t */\n\tpublic void setSlidingActionBarEnabled(boolean slidingActionBarEnabled) {\n\t\tif (mOnPostCreateCalled)\n\t\t\tthrow new IllegalStateException(\"enableSlidingActionBar must be called in onCreate.\");\n\t\tmEnableSlide = slidingActionBarEnabled;\n\t}\n\n\t/**\n\t * Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).\n\t * \n\t * @param id the resource id of the desired view\n\t * @return The view if found or null otherwise.\n\t */\n\tpublic View findViewById(int id) {\n\t\tView v;\n\t\tif (mSlidingMenu != null) {\n\t\t\tv = mSlidingMenu.findViewById(id);\n\t\t\tif (v != null)\n\t\t\t\treturn v;\n\t\t}\n\t\treturn null;\n\t}","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jfeinstein10/SlidingMenu/blob/4254feca3ece9397cd501921ee733f19ea0fdad8/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityHelper.java#L79-L115","documentation":"setSlidingActionBarEnabled() must be called during onCreate, before SlidingActivityHelper.onPostCreate() attaches the SlidingMenu to the Activity. Once mOnPostCreateCalled is true the menu is already built, so changing the ActionBar-sliding flag throws IllegalStateException.","triggerScenarios":"Calling setSlidingActionBarEnabled() in onResume, onStart, onPostCreate, or any point after onPostCreate has run; calling it after configuration change outside onCreate.","commonSituations":"Toggling the sliding ActionBar in response to user action at runtime; moving the call out of onCreate during a refactor; calling it in a fragment's lifecycle callback.","solutions":["Move the setSlidingActionBarEnabled(true/false) call into onCreate (before onPostCreate)","If runtime toggling is needed, recreate the activity or create a fresh SlidingMenu instance","Use a field set before onCreate completes and pass it to setSlidingActionBarEnabled in onCreate"],"exampleFix":"// before\nprotected void onResume() { super.onResume(); setSlidingActionBarEnabled(true); } // throws\n// after\nprotected void onCreate(Bundle b) {\n    super.onCreate(b);\n    setSlidingActionBarEnabled(true);\n    setBehindContentView(R.layout.menu_frame);\n}","handlingStrategy":"validation","validationCode":"// call only inside onCreate, before onPostComplete:\n@Override protected void onCreate(Bundle b) { super.onCreate(b); setSlidingActionBarEnabled(true); setBehindContentView(R.layout.menu_frame); }","typeGuard":null,"tryCatchPattern":"try { setSlidingActionBarEnabled(enabled); } catch (IllegalStateException e) { // too late; recreate activity to apply }","preventionTips":["Invoke setSlidingActionBarEnabled only in onCreate","Never toggle it from onResume/click handlers","Store the desired flag and apply it during onCreate on activity recreation"],"tags":["android","slidingmenu","lifecycle","call-timing"],"backgroundTag":"invalid-state-transition","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"}