{"record":{"id":"68364c5f5007c699","repo":"yuliskov/SmartTube","slug":"callback-may-not-be-null","errorCode":null,"errorMessage":"Callback may not be null","messagePattern":"Callback may not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"slidableactivity/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java","lineNumber":345,"sourceCode":"        final ViewDragHelper helper = create(forParent, 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     *\n     * @param context   Context to initialize config-dependent params from\n     * @param forParent Parent view to monitor\n     */\n    private ViewDragHelper(Context context, ViewGroup forParent, 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        mParentView = forParent;\n        mCallback = cb;\n        final ViewConfiguration vc = ViewConfiguration.get(context);\n        final float density = context.getResources().getDisplayMetrics().density;\n        mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);\n        mTouchSlop = vc.getScaledTouchSlop();\n        mMaxVelocity = vc.getScaledMaximumFlingVelocity();\n        mMinVelocity = vc.getScaledMinimumFlingVelocity();\n        mScroller = ScrollerCompat.create(context, sInterpolator);\n    }\n\n    /**\n     * Set the minimum velocity that will be detected as having a magnitude greater than zero\n     * in pixels per second. Callback methods accepting a velocity will be clamped appropriately.\n     *\n     * @param minVel Minimum velocity to detect\n     */","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/slidableactivity/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java#L327-L363","documentation":"ViewDragHelper's constructor also requires a non-null Callback — the callback supplies every drag decision (tryCaptureView, clampViewPosition, onViewReleased, ...), so a helper without one cannot function and the constructor throws IllegalArgumentException('Callback may not be null').","triggerScenarios":"ViewDragHelper.create(context, parent, null): commonly a callback field not yet assigned when create() runs (ordering bug in initialization), an anonymous callback accidentally not constructed, or a Kotlin property still null at call time.","commonSituations":"The helper is created in the constructor but the callback is assigned later in onCreate/onViewCreated; refactoring moved callback construction after create(); subclasses forgetting to pass their callback through.","solutions":["Construct the Callback before ViewDragHelper.create() and pass the same instance.","Reorder initialization so the callback field is assigned first, or inline the anonymous/lambda callback in the create() call.","In Kotlin, make the callback a val initialized at declaration or pass it as a constructor parameter so it can never be null at create() time."],"exampleFix":"// before\nprivate ViewDragHelper mHelper;\nprivate MyDragCallback mCallback; // still null here\nvoid setup() {\n    mHelper = ViewDragHelper.create(this, parent, mCallback); // throws\n    mCallback = new MyDragCallback();\n}\n\n// after\nvoid setup() {\n    mCallback = new MyDragCallback();\n    mHelper = ViewDragHelper.create(this, parent, mCallback);\n}","handlingStrategy":"validation","validationCode":"if (mCallback != null) {\n    mHelper = ViewDragHelper.create(this, parent, mCallback);\n} else {\n    Log.e(TAG, \"drag callback not initialized before create()\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize the Callback field before the create() call — order matters.","Prefer constructing the callback inline in the create() arguments.","In Kotlin, make the callback a val so it cannot be null at create() time."],"tags":["android","view","null-check","callback","drag"],"backgroundTag":"null-callback-parameter","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}