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

  1. Clear the RecyclerView's saved state / adapter state so stale view types are not requested
  2. Ensure models use unique view types and that all models bound to the adapter are still registered
  3. Update epoxy-adapter so model and adapter view-type generation are in sync
  4. 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

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


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)