{"record":{"id":"37d10c8c5b32cea1","repo":"Tencent/QMUI_Android","slug":"thumbview-must-be-a-instance-of-view","errorCode":null,"errorMessage":"thumbView must be a instance of View","messagePattern":"thumbView must be a instance of View","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/QMUISlider.java","lineNumber":130,"sourceCode":"                R.styleable.QMUISlider_qmui_slider_bar_use_clip_children_by_developer, false);\n        if (!useClipChildrenByDeveloper) {\n            int paddingHor = array.getDimensionPixelOffset(\n                    R.styleable.QMUISlider_qmui_slider_bar_padding_hor_for_thumb_shadow, 0);\n            int paddingVer = array.getDimensionPixelOffset(\n                    R.styleable.QMUISlider_qmui_slider_bar_padding_ver_for_thumb_shadow, 0);\n            setPadding(paddingHor, paddingVer, paddingHor, paddingVer);\n        }\n        array.recycle();\n        mBarPaint = new Paint();\n        mBarPaint.setStyle(Paint.Style.FILL);\n        mBarPaint.setAntiAlias(true);\n        mTouchSlop = QMUIDisplayHelper.dp2px(context, 2);\n        setWillNotDraw(false);\n        setClipToPadding(false);\n        setClipChildren(false);\n        IThumbView thumbView = onCreateThumbView(context, thumbSize, thumbStyleAttr);\n        if (!(thumbView instanceof View)) {\n            throw new IllegalArgumentException(\"thumbView must be a instance of View\");\n        }\n        mThumbView = thumbView;\n        View thumbAsView = (View) thumbView;\n        mThumbViewOffsetHelper = new QMUIViewOffsetHelper(thumbAsView);\n        addView(thumbAsView, onCreateThumbLayoutParams());\n        thumbView.render(mCurrentProgress, mTickCount);\n    }\n\n    public void setCallback(Callback callback) {\n        mCallback = callback;\n    }\n\n    public void setCurrentProgress(int currentProgress) {\n        if (!mIsMoving) {\n            int progress = QMUILangHelper.constrain(currentProgress, 0, mTickCount);\n            if (mCurrentProgress != progress || !mIsProgressFirstSet) {\n                mIsProgressFirstSet = true;\n                safeSetCurrentProgress(progress);","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/QMUISlider.java#L112-L148","documentation":"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.","triggerScenarios":"Subclassing QMUISlider and overriding onCreateThumbView(...) to return a custom IThumbView implementation that is not a View subclass.","commonSituations":"Custom thumb drawn with a separate renderer/Canvas object not tied to a View, or copying an IThumbView implementation from non-View widget code.","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."],"exampleFix":"// before\nprotected IThumbView onCreateThumbView(Context c, int size, int attr) {\n    return new MyThumbRenderer(); // not a View -> throws\n}\n// after\nprotected IThumbView onCreateThumbView(Context c, int size, int attr) {\n    return new MyThumbView(c); // class MyThumbView extends View implements IThumbView\n}","handlingStrategy":"type-guard","validationCode":"IThumbView tv = onCreateThumbView(context, size, attr);\nif (!(tv instanceof View)) {\n    throw new IllegalStateException(\"Custom thumb must extend View\");\n}","typeGuard":"boolean isValidThumb(IThumbView t) { return t instanceof View; }","tryCatchPattern":"try {\n    QMUISlider slider = new MySlider(context, thumbSize, thumbAttr);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"onCreateThumbView must return a View-backed IThumbView\", e);\n}","preventionTips":["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."],"tags":["android","qmui","type-mismatch","custom-view"],"backgroundTag":"type-mismatch","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}