yuliskov/SmartTube · error · IllegalArgumentException
You can't set adapter to DialogsList. Use #setAdapter(Dialog
Error message
You can't set adapter to DialogsList. Use #setAdapter(DialogsListAdapter) instead.
What it means
DialogsList is a styled RecyclerView that only works with its own adapter. The library overrides RecyclerView.setAdapter(Adapter) to throw IllegalArgumentException immediately, forcing you onto the typed overload setAdapter(DialogsListAdapter), which also wires click and long-click handling. The throw is synchronous at the setAdapter call, not during layout.
Source
Thrown at chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java:68
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
LinearLayoutManager layout = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
SimpleItemAnimator animator = new DefaultItemAnimator();
setLayoutManager(layout);
setItemAnimator(animator);
}
/**
* Don't use this method for setting your adapter, otherwise exception will by thrown.
* Call {@link #setAdapter(DialogsListAdapter)} instead.
*/
@Override
public void setAdapter(Adapter adapter) {
throw new IllegalArgumentException("You can't set adapter to DialogsList. Use #setAdapter(DialogsListAdapter) instead.");
}
/**
* Sets adapter for DialogsList
*
* @param adapter Adapter. Must extend DialogsListAdapter
* @param <DIALOG> Dialog model class
*/
public <DIALOG extends IDialog<?>>
void setAdapter(DialogsListAdapter<DIALOG> adapter) {
setAdapter(adapter, false);
}
/**
* Sets adapter for DialogsList
*
* @param adapter Adapter. Must extend DialogsListAdapter
* @param reverseLayout weather to use reverse layout for layout manager.View on GitHub (pinned to 3de8d90593)
Solutions
- Call the typed overload: dialogsList.setAdapter(new DialogsListAdapter<>(...))
- Declare your adapter variable as DialogsListAdapter<DIALOG>, not Adapter, so the typed overload is selected
- Remove any framework/testing code that sets a generic adapter on the list
Example fix
// before RecyclerView.Adapter adapter = new MyOldAdapter(); dialogsList.setAdapter(adapter); // throws IllegalArgumentException // after DialogsListAdapter<Dialog> adapter = new DialogsListAdapter<>(R.layout.item_dialog, null, imageLoader); dialogsList.setAdapter(adapter);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(adapter instanceof DialogsListAdapter)) {
throw new IllegalArgumentException("DialogsList requires a DialogsListAdapter");
}
dialogsList.setAdapter((DialogsListAdapter<?>) adapter); Type guard
static boolean isDialogsListAdapter(@Nullable Adapter a) {
return a instanceof DialogsListAdapter;
} Prevention
- Always declare adapter variables as DialogsListAdapter<DIALOG>, never as Adapter
- Do not copy plain RecyclerView wiring into DialogsList screens
- Wrap third-party code that injects adapters via the base signature behind your own typed helper
When it happens
Trigger: Calling dialogsList.setAdapter(adapter) where adapter is declared as RecyclerView.Adapter/Adapter (raw), so overload resolution binds to the overridden base method; passing any adapter that is not a DialogsListAdapter, including a DialogsListAdapter referenced through a supertype variable.
Common situations: Porting a plain RecyclerView chat screen to DialogsList and keeping the old setAdapter call; Kotlin calls where the variable type makes the compiler pick the Adapter overload; test or data-binding helpers that inject adapters through the base-class signature.
Related errors
- You can't set adapter to MessagesList. Use #setAdapter(Messa
- Wrong message view type. Please, report this issue on GitHub
- You must pass either Activity, Fragment or SupportFragment
- content type must be greater or less than '0'!
- Somehow we couldn't create the ViewHolder for message. Pleas
AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22).
Data as JSON: /api/errors/56596d4bdc09f2c4.
Report an issue: GitHub.