ybq/Android-SpinKit · error · IllegalArgumentException
this d must be instanceof Sprite
Error message
this d must be instanceof Sprite
What it means
SpinKitView only accepts drawables that are instances of the library's own Sprite abstract class. The framework's setIndeterminateDrawable(Drawable) is overridden and throws IllegalArgumentException when passed any other Drawable, because the spinner's animation logic works exclusively on Sprite objects.
Solutions
- Pass a Sprite instance: new SpinKitView.Builder(context).setStyle(Style.WAVE).build(), or use SpriteFactory to create one
- If loading from XML, ensure the drawable declared is one of the library's Sprite classes, and cast/verify it before calling setIndeterminateDrawable
- If you need a custom drawable, subclass Sprite (or DoubleClickListener-free SpriteDrawable) instead of a plain Drawable
- Guard with instanceof before calling, and fall back to SpriteFactory.create() on non-Sprite drawables
Example fix
// before spinKitView.setIndeterminateDrawable(ContextCompat.getDrawable(context, R.drawable.custom_loader)); // after Sprite sprite = SpriteFactory.create(context, Style.WAVE); spinKitView.setIndeterminateDrawable(sprite);
Defensive patterns
Strategy: type-guard
Validate before calling
if (drawable instanceof Sprite) { view.setIndeterminateDrawable(drawable); } else { view.setIndeterminateDrawable(SpriteFactory.create(context, Style.WAVE)); } Type guard
boolean isSpriteDrawable(Drawable d) { return d instanceof Sprite; } Try / catch
try { view.setIndeterminateDrawable(drawable); } catch (IllegalArgumentException e) { view.setIndeterminateDrawable(SpriteFactory.create(context, Style.WAVE)); } Prevention
- Always create spinner drawables via SpriteFactory or the SpinKitView.Builder style API
- Never pass drawables inflated from XML unless they are confirmed Sprite subclasses
- Add an instanceof assertion in your own wrapper around setIndeterminateDrawable
When it happens
Trigger: Calling setIndeterminateDrawable() (or init via constructor) on a SpinKitView with a Drawable that is not a Sprite subclass, e.g. a ColorDrawable, GradientDrawable, or a drawable inflated from XML via getDrawable().
Common situations: Developers inflate a spinner drawable from XML resources (which returns a plain Drawable), or pass system drawables instead of using SpinKitView's built-in Sprite styles such as Wave, RotatingPlane, or ChasingDots.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of ybq/Android-SpinKit@aa83e4d0a4 (2026-09-12).
Data as JSON: /api/errors/5207ff5bb30c8bac.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java:57
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr,
defStyleRes);
mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)];
mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE);
a.recycle();
init();
setIndeterminate(true);
}
private void init() {
Sprite sprite = SpriteFactory.create(mStyle);
sprite.setColor(mColor);
setIndeterminateDrawable(sprite);
}
@Override
public void setIndeterminateDrawable(Drawable d) {
if (!(d instanceof Sprite)) {
throw new IllegalArgumentException("this d must be instanceof Sprite");
}
setIndeterminateDrawable((Sprite) d);
}
public void setIndeterminateDrawable(Sprite d) {
super.setIndeterminateDrawable(d);
mSprite = d;
if (mSprite.getColor() == 0) {
mSprite.setColor(mColor);
}
onSizeChanged(getWidth(), getHeight(), getWidth(), getHeight());
if (getVisibility() == VISIBLE) {
mSprite.start();
}
}
View on GitHub (pinned to aa83e4d0a4)