DrKLO/Telegram · error · IllegalArgumentException
Drawable cannot be null.
Error message
Drawable cannot be null.
What it means
DividerItemDecoration requires a non-null Drawable to draw the divider line; a null mDivider would cause an NPE deep in Canvas.draw during onDraw. setDrawable is annotated @NonNull and checks the argument defensively so the failure is reported at configuration time with a clear message rather than as an opaque NPE during draw. The most common cause is passing getResources().getDrawable(id) which returns null on certain configurations or before resources are ready, or passing a drawable that failed to load.
Source
Thrown at TMessagesProj/src/main/java/androidx/recyclerview/widget/DividerItemDecoration.java:98
*
* @param orientation {@link #HORIZONTAL} or {@link #VERTICAL}
*/
public void setOrientation(int orientation) {
if (orientation != HORIZONTAL && orientation != VERTICAL) {
throw new IllegalArgumentException(
"Invalid orientation. It should be either HORIZONTAL or VERTICAL");
}
mOrientation = orientation;
}
/**
* Sets the {@link Drawable} for this divider.
*
* @param drawable Drawable that should be used as a divider.
*/
public void setDrawable(@NonNull Drawable drawable) {
if (drawable == null) {
throw new IllegalArgumentException("Drawable cannot be null.");
}
mDivider = drawable;
}
/**
* @return the {@link Drawable} for this divider.
*/
@Nullable
public Drawable getDrawable() {
return mDivider;
}
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (parent.getLayoutManager() == null || mDivider == null) {
return;
}
if (mOrientation == VERTICAL) {View on GitHub (pinned to 45ab8f4308)
Solutions
- Resolve the Drawable before passing it and null-check the result.
- If you need no divider, remove the DividerItemDecoration from the RecyclerView instead of setting a null drawable.
- Use AppCompatResources.getDrawable(context, R.drawable.x) which never returns null for valid resources (throws otherwise, surfacing the real problem).
Example fix
// before
did.setDrawable(getDrawable(R.drawable.missing)); // may be null
// after
Drawable d = AppCompatResources.getDrawable(this, R.drawable.divider);
if (d != null) {
did.setDrawable(d);
} else {
recyclerView.removeItemDecoration(did);
} Defensive patterns
Strategy: type-guard
Validate before calling
// Resolve drawable and guard against null
Drawable d = AppCompatResources.getDrawable(context, resId);
if (d != null) {
dividerItemDecoration.setDrawable(d);
} else {
recyclerView.removeItemDecoration(dividerItemDecoration);
} Type guard
// Java: null-check at the boundary
boolean isValidDrawable(Drawable d) { return d != null; } Prevention
- Use AppCompatResources.getDrawable which never returns null for valid ids.
- To clear a divider, remove the ItemDecoration rather than passing null.
- Validate resource ids from themes/attrs are non-zero before resolving.
When it happens
Trigger: Passing ContextCompat.getDrawable(context, resId) when resId is 0/invalid; passing a Drawable loaded from a stream that returned null; calling setDrawable(null) intentionally to 'clear' the divider (the API does not support null).
Common situations: Reading a divider resource id from a theme/attr that resolves to 0; using getDrawable on a resource missing from some density buckets; a runtime resource overlay that removed the drawable.
Related errors
- Invalid orientation. It should be either HORIZONTAL or VERTI
- should not dispatch add or move for pre layout
- op should be remove or update.{}
- only remove and update ops can be dispatched in first pass
- Unknown update op type for {}
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/77bbd8de13ff067e.
Report an issue: GitHub.