airbnb/epoxy · error · UnsupportedOperationException

Layout resources are unsupported. Views must be created…

Error message

Layout resources are unsupported. Views must be created with `buildView`

What it means

EpoxyModelWithView builds its view programmatically via buildView(parent) instead of inflating a layout resource, so getDefaultLayout — which EpoxyModel relies on for normal layout-based models — is deliberately unsupported and always throws UnsupportedOperationException.

Solutions

  1. Implement buildView(ViewGroup) in your EpoxyModelWithView subclass and construct the view in code
  2. Never rely on layout resources for this model type; use buildView for all view creation
  3. If you need XML layouts, extend EpoxyModel (with layout res) instead of EpoxyModelWithView

Example fix

// before
@Override
protected int getDefaultLayout() { return R.layout.item; } // on EpoxyModelWithView
// after
@Override
public MyView buildView(@NonNull ViewGroup parent) {
  return new MyView(parent.getContext());
}
Defensive patterns

Strategy: validation

Validate before calling

if (model instanceof EpoxyModelWithView) { assert model.buildView != null; }

Type guard

boolean usesProgrammaticView(EpoxyModel<?> m) { return m instanceof EpoxyModelWithView; }

Try / catch

try { controller.requestModelBuild(); } catch (UnsupportedOperationException e) { Log.e(TAG, "layout() not supported for view-built models", e); }

Prevention

When it happens

Trigger: Anything that causes EpoxyModelWithView.getDefaultLayout() to be invoked: using view-type/layout-resolution paths that ask the model for a default layout resource.

Common situations: Mixing EpoxyModelWithView models with APIs that expect layout-resource-based models; calling internal layout resolution on a programmatic-view model.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of airbnb/epoxy@e45bd3a61f (2026-09-13). Data as JSON: /api/errors/0251ccfb2985a96e. Report an issue: GitHub.

Appendix: source

Thrown at epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyModelWithView.java:49

   * @see androidx.recyclerview.widget.RecyclerView.Adapter#getItemViewType(int)
   */
  @Override
  protected int getViewType() {
    return 0;
  }

  /**
   * Create and return a new instance of a view for this model. If no layout params are set on the
   * returned view then default layout params will be used.
   *
   * @param parent The parent ViewGroup that the returned view will be added to.
   */
  @Override
  public abstract T buildView(@NonNull ViewGroup parent);

  @Override
  protected final int getDefaultLayout() {
    throw new UnsupportedOperationException(
        "Layout resources are unsupported. Views must be created with `buildView`");
  }

  @Override
  public EpoxyModel<T> layout(@LayoutRes int layoutRes) {
    throw new UnsupportedOperationException(
        "Layout resources are unsupported. Views must be created with `buildView`");
  }
}

View on GitHub (pinned to e45bd3a61f)