{"record":{"id":"82a19c2e6a02147c","repo":"DrKLO/Telegram","slug":"recyclerview-has-no-layoutmanager","errorCode":null,"errorMessage":"RecyclerView has no LayoutManager","messagePattern":"RecyclerView has no LayoutManager","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java","lineNumber":4519,"sourceCode":"    @Override\n    public void onDraw(Canvas c) {\n        super.onDraw(c);\n\n        final int count = mItemDecorations.size();\n        for (int i = 0; i < count; i++) {\n            mItemDecorations.get(i).onDraw(c, this, mState);\n        }\n    }\n\n    @Override\n    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {\n        return p instanceof LayoutParams && mLayout.checkLayoutParams((LayoutParams) p);\n    }\n\n    @Override\n    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {\n        if (mLayout == null) {\n            throw new IllegalStateException(\"RecyclerView has no LayoutManager\" + exceptionLabel());\n        }\n        return mLayout.generateDefaultLayoutParams();\n    }\n\n    @Override\n    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {\n        if (mLayout == null) {\n            throw new IllegalStateException(\"RecyclerView has no LayoutManager\" + exceptionLabel());\n        }\n        return mLayout.generateLayoutParams(getContext(), attrs);\n    }\n\n    @Override\n    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {\n        if (mLayout == null) {\n            throw new IllegalStateException(\"RecyclerView has no LayoutManager\" + exceptionLabel());\n        }\n        return mLayout.generateLayoutParams(p);","sourceCodeStart":4501,"sourceCodeEnd":4537,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java#L4501-L4537","documentation":"RecyclerView.generateDefaultLayoutParams throws IllegalStateException when mLayout (the LayoutManager) is null. generateDefaultLayoutParams is invoked by the ViewGroup framework when a child view added to the RecyclerView has no LayoutParams. A RecyclerView without a LayoutManager cannot produce valid LayoutParams (they are LayoutManager-specific), so the framework aborts rather than returning default ViewGroup params that would crash later during measurement.","triggerScenarios":"Adding a child view (directly via addView, or via inflate that parents into the RecyclerView) before a LayoutManager has been set via setLayoutManager(); instantiating RecyclerView programmatically and adding children before setLayoutManager; inflating a layout into the RecyclerView before assigning the manager.","commonSituations":"Dynamic RecyclerView creation in code where setLayoutManager is called after views are inserted; layout XML that declares RecyclerView children (RecyclerView children should be supplied by the adapter, never declared in XML); programmatic re-parenting of a view into a RecyclerView whose manager was cleared.","solutions":["Call recyclerView.setLayoutManager(...) before adding any child views or binding adapter content — typically immediately after instantiation.","Never declare RecyclerView children in XML; RecyclerView is a container whose children come exclusively from the adapter via the LayoutManager.","If clearing the manager, ensure no child views remain attached before the next measure pass (recyclerView.removeAllViews() then setLayoutManager(null))."],"exampleFix":"// before\nRecyclerView rv = new RecyclerView(ctx);\nrv.addView(customHeader); // throws: no LayoutManager\nrv.setLayoutManager(new LinearLayoutManager(ctx));\n// after\nRecyclerView rv = new RecyclerView(ctx);\nrv.setLayoutManager(new LinearLayoutManager(ctx));\nrv.addView(customHeader); // ok (though adapter is the normal path)","handlingStrategy":"validation","validationCode":"if (recyclerView.getLayoutManager() == null) {\n  recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));\n}\nrecyclerView.addView(child);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the LayoutManager immediately after constructing the RecyclerView (code or XML app:layoutManager).","Supply children only via the adapter, never via addView or XML declarations inside <RecyclerView>."],"tags":["recyclerview","layoutmanager","configuration","xml"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}