{"record":{"id":"56596d4bdc09f2c4","repo":"yuliskov/SmartTube","slug":"you-can-t-set-adapter-to-dialogslist-use-setadap","errorCode":null,"errorMessage":"You can't set adapter to DialogsList. Use #setAdapter(DialogsListAdapter) instead.","messagePattern":"You can't set adapter to DialogsList\\. Use #setAdapter\\(DialogsListAdapter\\) instead\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java","lineNumber":68,"sourceCode":"\n    @Override\n    protected void onAttachedToWindow() {\n        super.onAttachedToWindow();\n\n        LinearLayoutManager layout = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);\n        SimpleItemAnimator animator = new DefaultItemAnimator();\n\n        setLayoutManager(layout);\n        setItemAnimator(animator);\n    }\n\n    /**\n     * Don't use this method for setting your adapter, otherwise exception will by thrown.\n     * Call {@link #setAdapter(DialogsListAdapter)} instead.\n     */\n    @Override\n    public void setAdapter(Adapter adapter) {\n        throw new IllegalArgumentException(\"You can't set adapter to DialogsList. Use #setAdapter(DialogsListAdapter) instead.\");\n    }\n\n    /**\n     * Sets adapter for DialogsList\n     *\n     * @param adapter  Adapter. Must extend DialogsListAdapter\n     * @param <DIALOG> Dialog model class\n     */\n    public <DIALOG extends IDialog<?>>\n    void setAdapter(DialogsListAdapter<DIALOG> adapter) {\n        setAdapter(adapter, false);\n    }\n\n    /**\n     * Sets adapter for DialogsList\n     *\n     * @param adapter       Adapter. Must extend DialogsListAdapter\n     * @param reverseLayout weather to use reverse layout for layout manager.","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nRecyclerView.Adapter adapter = new MyOldAdapter();\ndialogsList.setAdapter(adapter); // throws IllegalArgumentException\n\n// after\nDialogsListAdapter<Dialog> adapter = new DialogsListAdapter<>(R.layout.item_dialog, null, imageLoader);\ndialogsList.setAdapter(adapter);","handlingStrategy":"type-guard","validationCode":"if (!(adapter instanceof DialogsListAdapter)) {\n    throw new IllegalArgumentException(\"DialogsList requires a DialogsListAdapter\");\n}\ndialogsList.setAdapter((DialogsListAdapter<?>) adapter);","typeGuard":"static boolean isDialogsListAdapter(@Nullable Adapter a) {\n    return a instanceof DialogsListAdapter;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["android","recyclerview","chatkit","adapter","api-misuse"],"backgroundTag":"adapter-type-mismatch","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}