jfeinstein10/SlidingMenu · error · IllegalStateException

SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT

Error message

SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT

What it means

An IllegalStateException guard thrown by SlidingMenu.setMode(int) when the supplied mode integer is not one of the three supported constants (SlidingMenu.LEFT, SlidingMenu.RIGHT, SlidingMenu.LEFT_RIGHT). It is a generic sentinel validation: the input at fault is the raw mode value passed to setMode, typically a mistyped constant, an arbitrary int, or a value read from unvalidated configuration or from onCheckedChanged handlers wiring the wrong checkbox/radio values. Callers must pass exactly one of the declared constants.

Solutions

  1. Use only SlidingMenu.LEFT, SlidingMenu.RIGHT, or SlidingMenu.LEFT_RIGHT
  2. Replace gravity/other constants with the SlidingMenu constants
  3. Wrap in try-catch or validate the mode int before calling

Example fix

// before
slidingMenu.setMode(Gravity.START);
// after
slidingMenu.setMode(SlidingMenu.LEFT);
Defensive patterns

Strategy: validation

Validate before calling

if (mode != SlidingMenu.LEFT && mode != SlidingMenu.RIGHT && mode != SlidingMenu.LEFT_RIGHT) throw new IllegalArgumentException("invalid mode: " + mode);
slidingMenu.setMode(mode);

Try / catch

try { slidingMenu.setMode(mode); } catch (IllegalStateException e) { slidingMenu.setMode(SlidingMenu.LEFT); }

Prevention

When it happens

Trigger: Calling setMode() with an arbitrary int, a constant from another class (e.g. Gravity.LEFT), or a computed value.

Common situations: Passing android.view.Gravity values instead of SlidingMenu constants; passing TOUCHMODE constants; saving/restoring mode as an int that was corrupted.

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/8f7dec4d61673cc9. Report an issue: GitHub.

Appendix: source

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

		mViewAbove.setSlidingEnabled(b);
	}

	/**
	 * Checks if is sliding enabled.
	 *
	 * @return true, if is sliding enabled
	 */
	public boolean isSlidingEnabled() {
		return mViewAbove.isSlidingEnabled();
	}

	/**
	 * Sets which side the SlidingMenu should appear on.
	 * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT
	 */
	public void setMode(int mode) {
		if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) {
			throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT");
		}
		mViewBehind.setMode(mode);
	}

	/**
	 * Returns the current side that the SlidingMenu is on.
	 * @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT
	 */
	public int getMode() {
		return mViewBehind.getMode();
	}

	/**
	 * Sets whether or not the SlidingMenu is in static mode (i.e. nothing is moving and everything is showing)
	 *
	 * @param b true to set static mode, false to disable static mode.
	 */
	public void setStatic(boolean b) {

View on GitHub (pinned to 4254feca3e)