jfeinstein10/SlidingMenu · critical · IllegalStateException

Both setBehindContentView must be called in onCreate in…

Error message

Both setBehindContentView must be called in onCreate in addition to setContentView.

What it means

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.

Solutions

  1. Call setBehindContentView(R.layout.menu_frame) in onCreate before onPostCreate
  2. Also call setContentView(R.layout.content_frame) in onCreate
  3. Ensure super.onCreate()/super.onPostCreate() are invoked so the helper runs at the right time
  4. Verify onCreate is not skipped (e.g. launching the activity through an unusual path)

Example fix

// before
protected void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.content); }
// after
protected void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.content_frame);
    setBehindContentView(R.layout.menu_frame);
}
Defensive patterns

Strategy: validation

Validate before calling

// in onCreate, before super.onPostCreate runs:
setContentView(R.layout.content_frame);
setBehindContentView(R.layout.menu_frame);

Try / catch

try { super.onPostCreate(savedInstanceState); } catch (IllegalStateException e) { throw new IllegalStateException("forgot setBehindContentView in onCreate", e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jfeinstein10/SlidingMenu@4254feca3e (2026-09-09). Data as JSON: /api/errors/de771e1aae6c8c39. Report an issue: GitHub.

Appendix: source

Thrown at library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityHelper.java:55

	}

	/**
	 * Sets mSlidingMenu as a newly inflated SlidingMenu. Should be called within the activitiy's onCreate()
	 *
	 * @param savedInstanceState the saved instance state (unused)
	 */
	public void onCreate(Bundle savedInstanceState) {
		mSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(R.layout.slidingmenumain, null);
	}

	/**
	 * Further SlidingMenu initialization. Should be called within the activitiy's onPostCreate()
	 *
	 * @param savedInstanceState the saved instance state (unused)
	 */
	public void onPostCreate(Bundle savedInstanceState) {
		if (mViewBehind == null || mViewAbove == null) {
			throw new IllegalStateException("Both setBehindContentView must be called " +
					"in onCreate in addition to setContentView.");
		}

		mOnPostCreateCalled = true;

		mSlidingMenu.attachToActivity(mActivity, 
				mEnableSlide ? SlidingMenu.SLIDING_WINDOW : SlidingMenu.SLIDING_CONTENT);
		
		final boolean open;
		final boolean secondary;
		if (savedInstanceState != null) {
			open = savedInstanceState.getBoolean("SlidingActivityHelper.open");
			secondary = savedInstanceState.getBoolean("SlidingActivityHelper.secondary");
		} else {
			open = false;
			secondary = false;
		}
		new Handler().post(new Runnable() {

View on GitHub (pinned to 4254feca3e)