{"record":{"id":"f9302ffa1b656864","repo":"Tencent/QMUI_Android","slug":"delegateview-must-be-a-instance-of-view","errorCode":null,"errorMessage":"delegateView must be a instance of View","messagePattern":"delegateView must be a instance of View","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/nestedScroll/QMUIContinuousNestedTopDelegateLayout.java","lineNumber":87,"sourceCode":"                                                 @Nullable AttributeSet attrs, int defStyleAttr) {\n        super(context, attrs, defStyleAttr);\n\n        mParentHelper = new NestedScrollingParentHelper(this);\n        mChildHelper = new NestedScrollingChildHelper(this);\n\n        ViewCompat.setNestedScrollingEnabled(this, true);\n        setClipToPadding(false);\n    }\n\n    public void setHeaderView(@NonNull View headerView) {\n        mHeaderView = headerView;\n        mHeaderViewOffsetHelper = new QMUIViewOffsetHelper(headerView);\n        addView(headerView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));\n    }\n\n    public void setDelegateView(@NonNull IQMUIContinuousNestedTopView delegateView) {\n        if (!(delegateView instanceof View)) {\n            throw new IllegalArgumentException(\"delegateView must be a instance of View\");\n        }\n        if (mDelegateView != null) {\n            mDelegateView.injectScrollNotifier(null);\n        }\n        mDelegateView = delegateView;\n        View view = (View) delegateView;\n        mDelegateViewOffsetHelper = new QMUIViewOffsetHelper(view);\n        // WRAP_CONTENT, the height will be handled by QMUIContinuousNestedTopAreaBehavior\n        addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));\n    }\n\n    public void setFooterView(@NonNull View footerView) {\n        mFooterView = footerView;\n        mFooterViewOffsetHelper = new QMUIViewOffsetHelper(footerView);\n        addView(footerView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));\n    }\n\n    @Override","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/nestedScroll/QMUIContinuousNestedTopDelegateLayout.java#L69-L105","documentation":"QMUIContinuousNestedTopDelegateLayout.setDelegateView() declares its parameter as IQMUIContinuousNestedTopView but defensively checks that it is also an android.view.View before calling addView/casting. In practice the instanceof View check is redundant for any normal implementation, so this IllegalArgumentException almost always signals a broken or null-backed implementation of the interface.","triggerScenarios":"Calling setDelegateView() with an IQMUIContinuousNestedTopView implementation that is not a View subclass — e.g. a proxy/mock implementation of the interface, or a dynamically generated implementation — or a null proxy passing the generic check.","commonSituations":"Seen in unit tests using Mockito/dynamic proxies for IQMUIContinuousNestedTopView, or extremely unusual custom implementations that extend Object only instead of a View class.","solutions":["Make the delegate a real View: extend a View/ViewGroup class AND implement IQMUIContinuousNestedTopView.","Use QMUI's stock implementations (QMUIContinuousNestedTopScrollLayout, QMUIContinuousNestedTopRecyclerView, QMUIContinuousNestedTopWebView).","In tests, pass a real View-based instance (or Robolectric view) instead of a mock implementing only the interface."],"exampleFix":"// before\nIQMUIContinuousNestedTopView delegate = mock(IQMUIContinuousNestedTopView.class); // not a View\ndelegateLayout.setDelegateView(delegate);\n\n// after\nIQMUIContinuousNestedTopView delegate = new QMUIContinuousNestedTopScrollLayout(context);\ndelegateLayout.setDelegateView(delegate);","handlingStrategy":"type-guard","validationCode":"if (!(delegateView instanceof View)) {\n    throw new IllegalArgumentException(\"delegateView must be a View\");\n}\ndelegateLayout.setDelegateView(delegateView);","typeGuard":"boolean isDelegateViewValid(IQMUIContinuousNestedTopView v) {\n    return v instanceof View;\n}","tryCatchPattern":"try {\n    delegateLayout.setDelegateView(delegateView);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"delegateView is not a View\", e);\n}","preventionTips":["Never mock IQMUIContinuousNestedTopView with plain interface proxies in production code","Ensure delegate classes extend a View/ViewGroup","Use Robolectric real views in tests"],"tags":["android","qmui","type-mismatch","illegal-argument"],"backgroundTag":"incompatible-source-type","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}