jfeinstein10/SlidingMenu · error · IllegalArgumentException

slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT

Error message

slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT

What it means

attachToActivity() only accepts the constants SlidingMenu.SLIDING_WINDOW or SlidingMenu.SLIDING_CONTENT as slideStyle; any other int throws IllegalArgumentException. The style controls whether the window decor (ActionBar area) or just the content view slides.

Solutions

  1. Pass SlidingMenu.SLIDING_WINDOW or SlidingMenu.SLIDING_CONTENT exactly
  2. Use the two-arg attachToActivity(activity, slideStyle) overload with a valid constant
  3. Check the call site for integer literals and replace with named constants

Example fix

// before
slidingMenu.attachToActivity(this, 1);
// after
slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
Defensive patterns

Strategy: validation

Validate before calling

if (slideStyle != SlidingMenu.SLIDING_WINDOW && slideStyle != SlidingMenu.SLIDING_CONTENT) throw new IllegalArgumentException("invalid slideStyle");

Try / catch

try { menu.attachToActivity(this, slideStyle); } catch (IllegalArgumentException e) { menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); }

Prevention

When it happens

Trigger: Calling attachToActivity(activity, someInt) with a hand-written int, a misremembered constant, or a value from another library.

Common situations: Typing 0/1 literals instead of the constants; passing a constant from a different enum (e.g. touch mode); refactor renaming that dropped the constant reference.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java:304

	 * Attaches the SlidingMenu to an entire Activity
	 * 
	 * @param activity the Activity
	 * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
	 */
	public void attachToActivity(Activity activity, int slideStyle) {
		attachToActivity(activity, slideStyle, false);
	}

	/**
	 * Attaches the SlidingMenu to an entire Activity
	 * 
	 * @param activity the Activity
	 * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
	 * @param actionbarOverlay whether or not the ActionBar is overlaid
	 */
	public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) {
		if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT)
			throw new IllegalArgumentException("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT");

		if (getParent() != null)
			throw new IllegalStateException("This SlidingMenu appears to already be attached");

		// get the window background
		TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
		int background = a.getResourceId(0, 0);
		a.recycle();

		switch (slideStyle) {
		case SLIDING_WINDOW:
			mActionbarOverlay = false;
			ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
			ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
			// save ActionBar themes that have transparent assets
			decorChild.setBackgroundResource(background);
			decor.removeView(decorChild);
			decor.addView(this);

View on GitHub (pinned to 4254feca3e)