bilibili/DanmakuFlameMaster · error · IllegalArgumentException
itemView may not be null
Error message
itemView may not be null
What it means
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.
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.
Example fix
// before new ViewCacheStuffer.ViewHolder(convertView) // convertView is null // after View itemView = LayoutInflater.from(ctx).inflate(R.layout.danmaku_item, parent, false); new ViewCacheStuffer.ViewHolder(itemView);
Defensive patterns
Strategy: validation
Validate before calling
if (itemView == null) { itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.danmaku_item, parent, false); }
ViewHolder holder = new ViewHolder(itemView); Type guard
boolean hasView = (itemView instanceof View);
Try / catch
try {
holder = new ViewHolder(itemView);
} catch (IllegalArgumentException e) {
holder = new ViewHolder(LayoutInflater.from(ctx).inflate(R.layout.danmaku_item, parent, false));
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of bilibili/DanmakuFlameMaster@e2846461a0 (2026-09-10).
Data as JSON: /api/errors/fc6013dfe70ccd6f.
Report an issue: GitHub.
Appendix: source
Thrown at DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/ViewCacheStuffer.java:22
import android.graphics.Paint;
import android.text.TextPaint;
import android.util.SparseArray;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
public abstract class ViewCacheStuffer<VH extends ViewCacheStuffer.ViewHolder> extends BaseCacheStuffer {
public static abstract class ViewHolder {
protected final View itemView;
public ViewHolder(View itemView) {
if (itemView == null) {
throw new IllegalArgumentException("itemView may not be null");
}
this.itemView = itemView;
}
public void measure(int widthMeasureSpec, int heightMeasureSpec) {
this.itemView.measure(widthMeasureSpec, heightMeasureSpec);
}
public int getMeasureWidth() {
return this.itemView.getMeasuredWidth();
}
public int getMeasureHeight() {
return this.itemView.getMeasuredHeight();
}
public void layout(int l, int t, int r, int b) {
this.itemView.layout(l, t, r, b);View on GitHub (pinned to e2846461a0)