Tencent/QMUI_Android · error · IllegalArgumentException
thumbView must be a instance of View
Error message
thumbView must be a instance of View
What it means
In its constructor, QMUISlider creates the thumb view via onCreateThumbView and requires the returned IThumbView to also be a View instance, since it must be attached as a child view with an offset helper. A custom thumb that implements IThumbView but doesn't extend View triggers this IllegalArgumentException.
Source
Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/QMUISlider.java:130
R.styleable.QMUISlider_qmui_slider_bar_use_clip_children_by_developer, false);
if (!useClipChildrenByDeveloper) {
int paddingHor = array.getDimensionPixelOffset(
R.styleable.QMUISlider_qmui_slider_bar_padding_hor_for_thumb_shadow, 0);
int paddingVer = array.getDimensionPixelOffset(
R.styleable.QMUISlider_qmui_slider_bar_padding_ver_for_thumb_shadow, 0);
setPadding(paddingHor, paddingVer, paddingHor, paddingVer);
}
array.recycle();
mBarPaint = new Paint();
mBarPaint.setStyle(Paint.Style.FILL);
mBarPaint.setAntiAlias(true);
mTouchSlop = QMUIDisplayHelper.dp2px(context, 2);
setWillNotDraw(false);
setClipToPadding(false);
setClipChildren(false);
IThumbView thumbView = onCreateThumbView(context, thumbSize, thumbStyleAttr);
if (!(thumbView instanceof View)) {
throw new IllegalArgumentException("thumbView must be a instance of View");
}
mThumbView = thumbView;
View thumbAsView = (View) thumbView;
mThumbViewOffsetHelper = new QMUIViewOffsetHelper(thumbAsView);
addView(thumbAsView, onCreateThumbLayoutParams());
thumbView.render(mCurrentProgress, mTickCount);
}
public void setCallback(Callback callback) {
mCallback = callback;
}
public void setCurrentProgress(int currentProgress) {
if (!mIsMoving) {
int progress = QMUILangHelper.constrain(currentProgress, 0, mTickCount);
if (mCurrentProgress != progress || !mIsProgressFirstSet) {
mIsProgressFirstSet = true;
safeSetCurrentProgress(progress);View on GitHub (pinned to 026e7d4866)
Solutions
- Make the custom thumb class extend View (e.g. View or a drawable-backed custom View) while implementing IThumbView.
- Wrap your renderer inside a small View subclass that delegates rendering in onDraw().
- If you don't need a custom thumb, don't override onCreateThumbView and use the default implementation.
- Cast-check with instanceof View in your override before returning to fail fast in your own code.
Example fix
// before
protected IThumbView onCreateThumbView(Context c, int size, int attr) {
return new MyThumbRenderer(); // not a View -> throws
}
// after
protected IThumbView onCreateThumbView(Context c, int size, int attr) {
return new MyThumbView(c); // class MyThumbView extends View implements IThumbView
} Defensive patterns
Strategy: type-guard
Validate before calling
IThumbView tv = onCreateThumbView(context, size, attr);
if (!(tv instanceof View)) {
throw new IllegalStateException("Custom thumb must extend View");
} Type guard
boolean isValidThumb(IThumbView t) { return t instanceof View; } Try / catch
try {
QMUISlider slider = new MySlider(context, thumbSize, thumbAttr);
} catch (IllegalArgumentException e) {
Log.e(TAG, "onCreateThumbView must return a View-backed IThumbView", e);
} Prevention
- When overriding onCreateThumbView, make the returned class extend View and implement IThumbView.
- Add an instanceof View assertion inside your own override to fail at your code, not the library's.
- Use the default thumb unless custom drawing is truly required.
- Review custom IThumbView implementations copied from other widget code — they usually aren't Views.
When it happens
Trigger: Subclassing QMUISlider and overriding onCreateThumbView(...) to return a custom IThumbView implementation that is not a View subclass.
Common situations: Custom thumb drawn with a separate renderer/Canvas object not tied to a View, or copying an IThumbView implementation from non-View widget code.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- topView must implement from IQMUIContinuousNestedTopView
- bottomView must implement from IQMUIContinuousNestedBottomVi
- delegateView must be a instance of View
- refreshView must be a instance of IRefreshView
- Not support the type: %s
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/37d10c8c5b32cea1.
Report an issue: GitHub.