MuntashirAkon/AppManager · error · IllegalArgumentException
offset must be greater than or equal to 0
Error message
offset must be greater than or equal to 0
What it means
setExpandedOffset() requires a non-negative pixel offset from the expanded position. Negative offsets are physically meaningless on screen, so the behavior throws IllegalArgumentException. Valid values are >= 0 and must not exceed the half-expanded offset.
Solutions
- Pass a non-negative offset (clamp with Math.max(0, offset))
- Fix the computation/source that yields the negative value
- Also ensure the offset does not exceed the half-expanded offset
Example fix
// before behavior.setExpandedOffset(offsetPx); // after behavior.setExpandedOffset(Math.max(0, offsetPx));
Defensive patterns
Strategy: validation
Validate before calling
if (offset >= 0) behavior.setExpandedOffset(offset);
Try / catch
try {
behavior.setExpandedOffset(offset);
} catch (IllegalArgumentException e) {
behavior.setExpandedOffset(0);
} Prevention
- Clamp offsets with Math.max(0, offset)
- Verify dip-to-pixel conversions can't go negative
- Keep expandedOffset <= halfExpandedOffset
When it happens
Trigger: Calling setExpandedOffset(-1) or any negative int, typically from a computed dip-to-pixel conversion that produced a negative value or a sign error.
Common situations: Passing a negative margin/offset constant; computing offset from resources that resolve to negative values on some configurations.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- ratio must be a float value between 0 and 1
- Invalid state to get top offset:
- STATE_DRAGGING should not be set externally.|STATE_SETTLING…
- ADB command did not produce
- ADB daemon not running.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/f8fb47f7ecfd9cf0.
Report an issue: GitHub.
Appendix: source
Thrown at libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java:1076
*/
@FloatRange(from = 0.0f, to = 1.0f)
public float getHalfExpandedRatio() {
return halfExpandedRatio;
}
/**
* Determines the top offset of the BottomSheet in the {@link #STATE_EXPANDED} state when
* fitsToContent is false. The default value is 0, which results in the sheet matching the
* parent's top.
*
* @param offset an integer value greater than equal to 0, representing the {@link
* #STATE_EXPANDED} offset. Value must not exceed the offset in the half expanded state.
* @attr ref
* com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_expandedOffset
*/
public void setExpandedOffset(int offset) {
if (offset < 0) {
throw new IllegalArgumentException("offset must be greater than or equal to 0");
}
this.expandedOffset = offset;
updateDrawableForTargetState(state, /* animate= */ true);
}
/**
* Returns the current expanded offset. If {@code fitToContents} is true, it will automatically
* pick the offset depending on the height of the content.
*
* @attr ref
* com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_expandedOffset
*/
public int getExpandedOffset() {
return fitToContents
? fitToContentsOffset
: Math.max(expandedOffset, paddingTopSystemWindowInsets ? 0 : insetTop);
}
View on GitHub (pinned to 0152f468fc)