jfeinstein10/SlidingMenu · error · IllegalStateException
Cannot set both behindOffset and behindWidth for a…
Error message
Cannot set both behindOffset and behindWidth for a SlidingMenu
What it means
When inflating SlidingMenu from XML, the attributes behindOffset and behindWidth are mutually exclusive: the behind view's size is defined either as a fixed offset from the edge or an explicit width, never both. If both are set in the layout's styleable, the constructor throws IllegalStateException.
Solutions
- Remove either app:behindOffset or app:behindWidth from the XML declaration
- Keep behindOffset for margin-based layout or behindWidth for fixed-width menu
- Set one of them programmatically via setBehindOffset()/setBehindWidth() instead of XML
Example fix
// before (XML) app:behindOffset="100dp" app:behindWidth="300dp" // after (XML) app:behindOffset="100dp"
Defensive patterns
Strategy: validation
Validate before calling
// ensure only one of the two attributes is present in the style/attr set
if (hasBehindOffset && hasBehindWidth) throw new IllegalStateException("set only behindOffset OR behindWidth"); Try / catch
try { slidingMenu = new SlidingMenu(context, attrs); } catch (IllegalStateException e) { slidingMenu = new SlidingMenu(context); slidingMenu.setBehindOffset(offsetPx); } Prevention
- Pick one sizing strategy (offset vs width) per project and stick to it
- Audit merged styles/themes for duplicate attribute definitions
- Prefer programmatic configuration to avoid XML attribute merging surprises
When it happens
Trigger: Declaring both app:behindOffset and app:behindWidth on a <com.jeremyfeinstein.slidingmenu.lib.SlidingMenu> element in a layout XML, both resolving to values other than -1.
Common situations: Merging styles/themes that each set one of the two attributes; copy-pasting an example layout that already had behindOffset and then adding behindWidth; defaulting both in a style.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- The BehindFadeDegree must be between 0.0f and 1.0f
- slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT
- This SlidingMenu appears to already be attached
- SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT
- ScrollScale must be between 0 and 1
AI-assisted analysis of jfeinstein10/SlidingMenu@4254feca3e (2026-09-09).
Data as JSON: /api/errors/97b4b99847ca8c6a.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java:258
setContent(viewAbove);
} else {
setContent(new FrameLayout(context));
}
int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);
if (viewBehind != -1) {
setMenu(viewBehind);
} else {
setMenu(new FrameLayout(context));
}
int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);
setTouchModeAbove(touchModeAbove);
int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);
setTouchModeBehind(touchModeBehind);
int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1);
int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1);
if (offsetBehind != -1 && widthBehind != -1)
throw new IllegalStateException("Cannot set both behindOffset and behindWidth for a SlidingMenu");
else if (offsetBehind != -1)
setBehindOffset(offsetBehind);
else if (widthBehind != -1)
setBehindWidth(widthBehind);
else
setBehindOffset(0);
float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f);
setBehindScrollScale(scrollOffsetBehind);
int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);
if (shadowRes != -1) {
setShadowDrawable(shadowRes);
}
int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
setShadowWidth(shadowWidth);
boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);
setFadeEnabled(fadeEnabled);
float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);
setFadeDegree(fadeDeg);View on GitHub (pinned to 4254feca3e)