airbnb/epoxy · error · IllegalStateException
Could not find model for view type:
Error message
Could not find model for view type:
What it means
When the RecyclerView needs to create a view for a given view type, Epoxy looks up the model registered with that type. If no model matches the viewType (and it is not the hidden model's type), this IllegalStateException is thrown, indicating the adapter's view-type registry is out of sync with the models.
Solutions
- Clear the RecyclerView's saved state / adapter state so stale view types are not requested
- Ensure models use unique view types and that all models bound to the adapter are still registered
- Update epoxy-adapter so model and adapter view-type generation are in sync
- Rebuild the adapter's model list (epoxyRecyclerView.requestModelBuild or adapter.setModels) before layouts resume
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure adapter models are set before layout: check recyclerView.adapter != null and models list non-empty
Try / catch
try { recyclerView.adapter = epoxyAdapter } catch (e: IllegalStateException) { epoxyAdapter.requestRebuild(); recyclerView.adapter = epoxyAdapter } Prevention
- Clear RecyclerView saved state after major model list changes
- Keep model set and adapter updates atomic
- Avoid custom getViewType overrides that can collide
- Pin epoxy-adapter versions across modules
When it happens
Trigger: onCreateViewHolder receiving a viewType that no longer maps to any model — e.g., adapter models changed while a stale viewType is requested, or a custom getModelForViewType/viewType assignment collision.
Common situations: Updating the Epoxy library or changing model classes so generated view types shift while old layout state is restored; restoring RecyclerView state after a model list change; duplicate getViewType values from custom models.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Diffing is enabled. You should use notifyModelsChanged…
- Moving more than 1 item at a time is not supported. Number…
- UnboundedViewPool does not support setting a maximum number…
- Must have stable ids when saving view holder state
- State cannot be restored once views have been bound. It…
AI-assisted analysis of airbnb/epoxy@e45bd3a61f (2026-09-13).
Data as JSON: /api/errors/3b1b63f38f36108a.
Report an issue: GitHub.
Appendix: source
Thrown at epoxy-adapter/src/main/java/com/airbnb/epoxy/ViewTypeManager.java:92
}
adapter.onExceptionSwallowed(
new IllegalStateException("Last model did not match expected view type"));
// To be extra safe in case RecyclerView implementation details change...
for (EpoxyModel<?> model : adapter.getCurrentModels()) {
if (getViewType(model) == viewType) {
return model;
}
}
// Check for the hidden model.
HiddenEpoxyModel hiddenEpoxyModel = new HiddenEpoxyModel();
if (viewType == hiddenEpoxyModel.getViewType()) {
return hiddenEpoxyModel;
}
throw new IllegalStateException("Could not find model for view type: " + viewType);
}
}
View on GitHub (pinned to e45bd3a61f)