hackware1993/MagicIndicator · error · IllegalArgumentException
mode " + mode + " not supported.
Error message
mode " + mode + " not supported.
What it means
LinePagerIndicator.setMode() only accepts MODE_EXACTLY, MODE_MATCH_EDGE, or MODE_WRAP_CONTENT. Any other int (including values from another indicator's constants or a raw integer) throws IllegalArgumentException. It fails fast because an unsupported mode would produce undefined indicator sizing.
Solutions
- Use one of the three constants defined on LinePagerIndicator: MODE_EXACTLY, MODE_MATCH_EDGE, or MODE_WRAP_CONTENT
- Check that you are importing net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator and referencing its constants, not another class's
- If the mode comes from stored config/attributes, validate it against the three allowed values before calling setMode
Example fix
// before indicator.setMode(3); // after indicator.setMode(LinePagerIndicator.MODE_MATCH_EDGE);
Defensive patterns
Strategy: validation
Validate before calling
private static final int[] ALLOWED_MODES = {
LinePagerIndicator.MODE_EXACTLY,
LinePagerIndicator.MODE_MATCH_EDGE,
LinePagerIndicator.MODE_WRAP_CONTENT
};
static boolean isValidMode(int mode) {
for (int m : ALLOWED_MODES) {
if (m == mode) return true;
}
return false;
}
// before calling:
if (isValidMode(mode)) indicator.setMode(mode); Type guard
static boolean isLinePagerIndicatorMode(int mode) {
return mode == LinePagerIndicator.MODE_EXACTLY
|| mode == LinePagerIndicator.MODE_MATCH_EDGE
|| mode == LinePagerIndicator.MODE_WRAP_CONTENT;
} Try / catch
try {
indicator.setMode(mode);
} catch (IllegalArgumentException e) {
Log.w("MagicIndicator", "Unsupported mode " + mode + ", falling back", e);
indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
} Prevention
- Always reference the constants via LinePagerIndicator.MODE_* instead of raw ints
- Never share mode constants across different indicator classes
- Validate persisted/attr-sourced mode values before applying them
When it happens
Trigger: Calling setMode() with an int that is not one of LinePagerIndicator.MODE_EXACTLY, MODE_MATCH_EDGE, or MODE_WRAP_CONTENT — e.g. passing LinePagerIndicator.MODE_FIXED (which does not exist), a ViewPager.LayoutParams constant, or a literal like 3.
Common situations: Copy-pasting mode constants from a different indicator class (e.g. CommonPagerTitleView or CirclePagerIndicator), mistyping a constant name and resolving to a wrong int, or persisting/restoring mode as an int from preferences where the stored value is out of range.
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 hackware1993/MagicIndicator@fe22c7dc45 (2026-09-10).
Data as JSON: /api/errors/676f73aaa1fdd561.
Report an issue: GitHub.
Appendix: source
Thrown at magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/indicators/LinePagerIndicator.java:173
}
public float getRoundRadius() {
return mRoundRadius;
}
public void setRoundRadius(float roundRadius) {
mRoundRadius = roundRadius;
}
public int getMode() {
return mMode;
}
public void setMode(int mode) {
if (mode == MODE_EXACTLY || mode == MODE_MATCH_EDGE || mode == MODE_WRAP_CONTENT) {
mMode = mode;
} else {
throw new IllegalArgumentException("mode " + mode + " not supported.");
}
}
public Paint getPaint() {
return mPaint;
}
public List<Integer> getColors() {
return mColors;
}
public void setColors(Integer... colors) {
mColors = Arrays.asList(colors);
}
public Interpolator getStartInterpolator() {
return mStartInterpolator;
}
View on GitHub (pinned to fe22c7dc45)