{"record":{"id":"6421b468ba8d2d52","repo":"umano/AndroidSlidingUpPanel","slug":"parent-view-may-not-be-null","errorCode":null,"errorMessage":"Parent view may not be null","messagePattern":"Parent view may not be null","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java","lineNumber":406,"sourceCode":"    public static ViewDragHelper create(ViewGroup forParent, float sensitivity, Interpolator interpolator, Callback cb) {\n        final ViewDragHelper helper = create(forParent, interpolator, cb);\n        helper.mTouchSlop = (int) (helper.mTouchSlop * (1 / sensitivity));\n        return helper;\n    }\n\n    /**\n     * Apps should use ViewDragHelper.create() to get a new instance.\n     * This will allow VDH to use internal compatibility implementations for different\n     * platform versions.\n     * If the interpolator is null, the default interpolator will be used.\n     *\n     * @param context Context to initialize config-dependent params from\n     * @param forParent Parent view to monitor\n     * @param interpolator interpolator for scroller\n     */\n    private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interpolator, Callback cb) {\n        if (forParent == null) {\n            throw new IllegalArgumentException(\"Parent view may not be null\");\n        }\n        if (cb == null) {\n            throw new IllegalArgumentException(\"Callback may not be null\");\n        }\n\n        mParentView = forParent;\n        mCallback = cb;\n\n        final ViewConfiguration vc = ViewConfiguration.get(context);\n        final float density = context.getResources().getDisplayMetrics().density;\n        mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);\n\n        mTouchSlop = vc.getScaledTouchSlop();\n        mMaxVelocity = vc.getScaledMaximumFlingVelocity();\n        mMinVelocity = vc.getScaledMinimumFlingVelocity();\n        mScroller = ScrollerCompat.create(context, interpolator != null ? interpolator : sInterpolator);\n    }\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java#L388-L424","documentation":"ViewDragHelper's private constructor validates its arguments; creating a helper with a null parent ViewGroup throws IllegalArgumentException. The parent is the view whose drag events the helper monitors, so it is mandatory.","triggerScenarios":"Calling ViewDragHelper.create(null, cb) or any create(...) overload with a null forParent — typically when a view's getParent() is null (view not attached) or a field is not yet initialized.","commonSituations":"Constructing the helper in a custom View's field initializer before the parent exists, or passing a detached view's null parent.","solutions":["Always pass a non-null ViewGroup (usually 'this' from the custom view, not getParent())","Create the helper in onAttachedToWindow or the constructor with a valid reference","Null-check/initialize the view before helper creation"],"exampleFix":"// before\nmDragHelper = ViewDragHelper.create((ViewGroup) getParent(), callback);\n// after\nmDragHelper = ViewDragHelper.create(this, callback); // inside the custom ViewGroup","handlingStrategy":"type-guard","validationCode":"ViewGroup parent = (parentView != null) ? parentView : this;\nmDragHelper = ViewDragHelper.create(parent, sensitivity, callback);","typeGuard":"ViewGroup safeParent(ViewGroup v) { return v != null ? v : (ViewGroup) requireNotNull(getParent(), \"not attached yet\"); }","tryCatchPattern":null,"preventionTips":["Pass 'this' from the custom ViewGroup, not getParent()","Create the helper in onAttachedToWindow if parent needed","Never create helper before view inflation"],"tags":["android","viewdraghelper","null-argument"],"backgroundTag":"null-argument","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}