material-components/material-components-android · error · IllegalArgumentException
startIconSize cannot be less than 0
Error message
startIconSize cannot be less than 0
What it means
StartCompoundLayout.setStartIconMinSize validates that the minimum start-icon size is non-negative before applying it to the start icon view. Negative sizes are meaningless for view layout, so it throws IllegalArgumentException('startIconSize cannot be less than 0').
Source
Thrown at lib/java/com/google/android/material/textfield/StartCompoundLayout.java:294
}
void setStartIconTintList(@Nullable ColorStateList startIconTintList) {
if (this.startIconTintList != startIconTintList) {
this.startIconTintList = startIconTintList;
applyIconTint(textInputLayout, startIconView, startIconTintList, startIconTintMode);
}
}
void setStartIconTintMode(@Nullable PorterDuff.Mode startIconTintMode) {
if (this.startIconTintMode != startIconTintMode) {
this.startIconTintMode = startIconTintMode;
applyIconTint(textInputLayout, startIconView, startIconTintList, this.startIconTintMode);
}
}
void setStartIconMinSize(@Px int iconSize) {
if (iconSize < 0) {
throw new IllegalArgumentException("startIconSize cannot be less than 0");
}
if (iconSize != startIconMinSize) {
startIconMinSize = iconSize;
setIconMinSize(startIconView, iconSize);
}
}
int getStartIconMinSize() {
return startIconMinSize;
}
void setStartIconScaleType(@NonNull ScaleType startIconScaleType) {
this.startIconScaleType = startIconScaleType;
setIconScaleType(startIconView, startIconScaleType);
}
@NonNull
ScaleType getStartIconScaleType() {View on GitHub (pinned to ac7e18efee)
Solutions
- Pass a non-negative pixel size: setStartIconMinSize(getResources().getDimensionPixelSize(R.dimen.icon_min)).
- Guard config-driven values: only call the setter when size >= 0.
- Review app:startIconMinSize dimens for typos.
Example fix
// before til.setStartIconMinSize(iconSize); // iconSize == -1 sentinel -> throws // after if (iconSize >= 0) til.setStartIconMinSize(iconSize);
Defensive patterns
Strategy: validation
Validate before calling
if (iconMinSize >= 0) til.setStartIconMinSize(iconMinSize);
Prevention
- Guard config-driven sizes with >= 0 checks.
- Use dimension resources for icon sizes instead of computed raw ints.
- Share one validated size constant for start and end icons.
When it happens
Trigger: Calling setStartIconMinSize(-1) or any negative value; negative app:startIconMinSize dimension in XML.
Common situations: Sentinel -1 from unresolved settings or unselected config forwarded directly; dimension arithmetic that underflows; copy-paste between icon-size attributes with a sign mistake.
Related errors
- endIconSize cannot be less than 0
- Invalid end icon mode:
- > boxBackgroundMode < is illegal; only @BoxBackgroundMode co
- There must be a keyline marked as focal.
- No color resources provided for harmonization.
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/2d995a5bebc8629d.
Report an issue: GitHub.