jfeinstein10/SlidingMenu · error · IllegalStateException
TouchMode must be set to eitherTOUCHMODE_FULLSCREEN or…
Error message
TouchMode must be set to eitherTOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.
What it means
An IllegalStateException guard thrown by SlidingMenu.setTouchModeAbove(int) when the touch mode integer is not one of the three accepted constants (TOUCHMODE_FULLSCREEN, TOUCHMODE_MARGIN, TOUCHMODE_NONE). This is a generic sentinel validation: the input at fault is the raw int argument to setTouchModeAbove, usually an invalid literal, a wrong constant from another class, or unvalidated persisted settings. Only the declared TOUCHMODE_* constants are legal.
Solutions
- Pass only SlidingMenu.TOUCHMODE_FULLSCREEN, TOUCHMODE_MARGIN, or TOUCHMODE_NONE
- Validate any persisted/restored int against the three constants before applying
- Fall back to TOUCHMODE_MARGIN when the stored value is unknown
Example fix
// before
slidingMenu.setTouchModeAbove(prefs.getInt("touchmode", 99));
// after
int tm = prefs.getInt("touchmode", SlidingMenu.TOUCHMODE_MARGIN);
if (tm == SlidingMenu.TOUCHMODE_FULLSCREEN || tm == SlidingMenu.TOUCHMODE_MARGIN || tm == SlidingMenu.TOUCHMODE_NONE)
slidingMenu.setTouchModeAbove(tm); Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidTouchMode(int i) { return i == SlidingMenu.TOUCHMODE_FULLSCREEN || i == SlidingMenu.TOUCHMODE_MARGIN || i == SlidingMenu.TOUCHMODE_NONE; }
if (isValidTouchMode(tm)) slidingMenu.setTouchModeAbove(tm); Try / catch
try { slidingMenu.setTouchModeAbove(tm); } catch (IllegalStateException e) { slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); } Prevention
- Validate values restored from SharedPreferences
- Use only SlidingMenu TOUCHMODE_* constants
- Store the constant name (string) rather than raw int if persisting
When it happens
Trigger: Calling setTouchModeAbove() with an int that is not one of the three SlidingMenu touch-mode constants, e.g. a custom value or a constant from another class.
Common situations: Persisting the touch mode in SharedPreferences as an arbitrary int and restoring an invalid value; passing Gravity or edge constants; typo'd constant import.
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
- slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT
- SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT
- The BehindFadeDegree must be between 0.0f and 1.0f
- Cannot set both behindOffset and behindWidth for a…
- This SlidingMenu appears to already be attached
AI-assisted analysis of jfeinstein10/SlidingMenu@4254feca3e (2026-09-09).
Data as JSON: /api/errors/beec709760ed4db1.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java:720
* Gets the touch mode above.
*
* @return the touch mode above
*/
public int getTouchModeAbove() {
return mViewAbove.getTouchMode();
}
/**
* Controls whether the SlidingMenu can be opened with a swipe gesture.
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
*
* @param i the new touch mode
*/
public void setTouchModeAbove(int i) {
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
&& i != TOUCHMODE_NONE) {
throw new IllegalStateException("TouchMode must be set to either" +
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
}
mViewAbove.setTouchMode(i);
}
/**
* Controls whether the SlidingMenu can be opened with a swipe gesture.
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
*
* @param i the new touch mode
*/
public void setTouchModeBehind(int i) {
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
&& i != TOUCHMODE_NONE) {
throw new IllegalStateException("TouchMode must be set to either" +
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
}View on GitHub (pinned to 4254feca3e)