{"record":{"id":"fc6013dfe70ccd6f","repo":"bilibili/DanmakuFlameMaster","slug":"itemview-may-not-be-null","errorCode":null,"errorMessage":"itemView may not be null","messagePattern":"itemView may not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/ViewCacheStuffer.java","lineNumber":22,"sourceCode":"import android.graphics.Paint;\nimport android.text.TextPaint;\nimport android.util.SparseArray;\nimport android.view.View;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport master.flame.danmaku.danmaku.model.BaseDanmaku;\n\npublic abstract class ViewCacheStuffer<VH extends ViewCacheStuffer.ViewHolder> extends BaseCacheStuffer {\n\n    public static abstract class ViewHolder {\n\n        protected final View itemView;\n\n        public ViewHolder(View itemView) {\n            if (itemView == null) {\n                throw new IllegalArgumentException(\"itemView may not be null\");\n            }\n            this.itemView = itemView;\n        }\n\n        public void measure(int widthMeasureSpec, int heightMeasureSpec) {\n            this.itemView.measure(widthMeasureSpec, heightMeasureSpec);\n        }\n\n        public int getMeasureWidth() {\n            return this.itemView.getMeasuredWidth();\n        }\n\n        public int getMeasureHeight() {\n            return this.itemView.getMeasuredHeight();\n        }\n\n        public void layout(int l, int t, int r, int b) {\n            this.itemView.layout(l, t, r, b);","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/bilibili/DanmakuFlameMaster/blob/e2846461a09e33720a049f628f09c653f55531f0/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/ViewCacheStuffer.java#L4-L40","documentation":"ViewCacheStuffer.ViewHolder stores the Android View it will measure and display, so a null itemView is unusable. The abstract base class ViewHolder validates this in its constructor and throws IllegalArgumentException immediately.","triggerScenarios":"Subclassing ViewCacheStuffer.ViewHolder and passing null to super(itemView), e.g. new BaseViewHolder(null), typically when findViewById returned null or the layout was not inflated yet.","commonSituations":"Layout inflation failure leaving convertView/view null; reusing a ViewHolder pattern from RecyclerView where itemView was never bound; custom cache stuffer implementations passing a view obtained before setContentView/inflation.","solutions":["Pass an actually inflated View (e.g. LayoutInflater.inflate(...)) to the ViewHolder constructor.","Check that findViewById / convertView is non-null before constructing the ViewHolder.","Fix the layout inflation: verify the layout resource id and that inflate() is called before creating the holder."],"exampleFix":"// before\nnew ViewCacheStuffer.ViewHolder(convertView) // convertView is null\n// after\nView itemView = LayoutInflater.from(ctx).inflate(R.layout.danmaku_item, parent, false);\nnew ViewCacheStuffer.ViewHolder(itemView);","handlingStrategy":"validation","validationCode":"if (itemView == null) { itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.danmaku_item, parent, false); }\nViewHolder holder = new ViewHolder(itemView);","typeGuard":"boolean hasView = (itemView instanceof View);","tryCatchPattern":"try {\n    holder = new ViewHolder(itemView);\n} catch (IllegalArgumentException e) {\n    holder = new ViewHolder(LayoutInflater.from(ctx).inflate(R.layout.danmaku_item, parent, false));\n}","preventionTips":["Inflate layouts with LayoutInflater before creating ViewHolders.","Check convertView/findView results for null before binding.","Keep custom cache stuffers mirroring RecyclerView's non-null itemView contract."],"tags":["android","danmaku","null-argument","viewholder"],"backgroundTag":"null-argument","analyzedSha":"e2846461a09e33720a049f628f09c653f55531f0","analyzedAt":"2026-09-10T14:31:54.917Z","contentChangedAt":"2026-09-10T14:31:54.917Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}