{"record":{"id":"de5e9e2222431819","repo":"yuliskov/SmartTube","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":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"slidableactivity/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java","lineNumber":342,"sourceCode":"     * @return a new ViewDragHelper instance\n     */\n    public static ViewDragHelper create(ViewGroup forParent, float sensitivity, Callback cb) {\n        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.","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/slidableactivity/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java#L324-L360","documentation":"ViewDragHelper is Slidr's bundled copy of the framework drag helper used for slide-to-dismiss. Its constructor requires a non-null parent ViewGroup — the view whose children will be dragged — and throws IllegalArgumentException('Parent view may not be null') otherwise. You reach it through ViewDragHelper.create(context, forParent, callback).","triggerScenarios":"ViewDragHelper.create(context, null, callback): the parent argument is null because findViewById returned null (wrong ID, or called before setContentView/inflate) or because a nullable Kotlin view was passed without a check.","commonSituations":"Creating the helper in Activity.onCreate() before setContentView(); using the wrong layout ID so findViewById(R.id.container) resolves to null; fragments calling create() before onViewCreated; Kotlin call sites passing a not-yet-initialized view.","solutions":["Move ViewDragHelper.create() to after the view hierarchy exists — after setContentView() in an activity, or in onViewCreated()/onAttach() for fragments.","Verify the container ID exists in the inflated layout and that the cast to ViewGroup succeeds before calling create().","Pass the ViewGroup that directly contains the draggable children (for Slidr, the content view the slider attaches to).","Add a local null check with a descriptive message so the failure names your layout bug, not the library's."],"exampleFix":"// before\n@Override protected void onCreate(Bundle b) {\n    super.onCreate(b);\n    mHelper = ViewDragHelper.create(this, (ViewGroup) findViewById(R.id.container), mCallback); // null before setContentView\n    setContentView(R.layout.main);\n}\n\n// after\n@Override protected void onCreate(Bundle b) {\n    super.onCreate(b);\n    setContentView(R.layout.main);\n    ViewGroup parent = (ViewGroup) findViewById(R.id.container);\n    if (parent != null) {\n        mHelper = ViewDragHelper.create(this, parent, mCallback);\n    }\n}","handlingStrategy":"validation","validationCode":"View parent = findViewById(R.id.drag_container);\nif (parent instanceof ViewGroup) {\n    mHelper = ViewDragHelper.create(this, (ViewGroup) parent, mCallback);\n} else {\n    Log.e(TAG, \"drag_container missing in this layout\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the helper only after setContentView()/onViewCreated so findViewById can resolve.","Null-check and type-check the container before ViewDragHelper.create.","Use the exact layout id across layout variants (landscape/portrait)."],"tags":["android","view","null-check","drag","slide-to-dismiss"],"backgroundTag":"null-parent-view","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}