material-components/material-components-android · error · IllegalArgumentException
Email does not exist.
Error message
Email %d does not exist.
What it means
Thrown by the static lookup helper getEmailById(long) in the catalog's AdaptiveListViewDemoFragment. It iterates the hardcoded emailData list (Email objects with ids 1..9) and throws IllegalArgumentException when no Email matches the requested id. This is demo/sample data code, not library API.
Solutions
- Pass an id that exists in emailData — the demo defines Email objects with ids 1 through 9.
- If you adapted this demo, replace emailData with your own dataset and keep ids in sync with what you pass to getEmailById.
- Guard the call: check the id range (1..emailData.size()) before invoking getEmailById.
- Wrap the call in try/catch (IllegalArgumentException) only if a missing email is an expected, recoverable condition in your flow.
Example fix
// before Email email = AdaptiveListViewDemoFragment.getEmailById(42); // throws // after Email email = AdaptiveListViewDemoFragment.getEmailById(5); // id exists in emailData
Defensive patterns
Strategy: validation
Validate before calling
boolean emailExists = emailId >= 1 && emailId <= 9; // ids defined in emailData
if (emailExists) {
Email email = AdaptiveListViewDemoFragment.getEmailById(emailId);
} Try / catch
catch (IllegalArgumentException e) only at the boundary where a user-supplied id enters the demo flow; treat it as 'not found' and skip/degrade, never swallow silently.
Prevention
- Keep request ids sourced from the same dataset you look them up in.
- In adapted demo code, replace sample data wholesale rather than mixing real ids with sample ids.
When it happens
Trigger: Calling AdaptiveListViewDemoFragment.getEmailById(emailId) with an id that is not one of the ids present in the static emailData list (e.g. 0, negative values, or ids >= 10).
Common situations: Copy-pasting this catalog demo into your own app and passing ids from your real data model that do not match the sample range; off-by-one loops; passing an unset long (0) or a default id before data initialization.
Related errors
- Album does not exist.
- Color names need to be at least four and correspond to…
- Animator must be an ObjectAnimator:
- AppBarLayout is always vertical and does not support…
- cradleVerticalOffset must be positive.
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/e0f3af572bf290a1.
Report an issue: GitHub.
Appendix: source
Thrown at catalog/java/io/material/catalog/adaptive/AdaptiveListViewDemoFragment.java:251
Arrays.asList(
new Email(0L, true),
new Email(1L, false),
new Email(2L, false),
new Email(3L, false),
new Email(4L, false),
new Email(5L, false),
new Email(6L, false),
new Email(7L, false),
new Email(8L, false),
new Email(9L, false));
static Email getEmailById(long emailId) {
for (Email email : emailData) {
if (email.id == emailId) {
return email;
}
}
throw new IllegalArgumentException(
String.format(Locale.US, "Email %d does not exist.", emailId));
}
/** Class that represents an email. */
static class Email {
private final long id;
private boolean isSelected;
Email(long id, boolean isSelected) {
this.id = id;
this.isSelected = isSelected;
}
/** Returns the email id. */
public long getEmailId() {
return id;
}
View on GitHub (pinned to ac7e18efee)