yuliskov/SmartTube · error · IllegalArgumentException
Parent view may not be null
Error message
Parent view may not be null
What it means
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).
Source
Thrown at slidableactivity/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java:342
* @return a new ViewDragHelper instance
*/
public static ViewDragHelper create(ViewGroup forParent, float sensitivity, Callback cb) {
final ViewDragHelper helper = create(forParent, cb);
helper.mTouchSlop = (int) (helper.mTouchSlop * (1 / sensitivity));
return helper;
}
/**
* Apps should use ViewDragHelper.create() to get a new instance.
* This will allow VDH to use internal compatibility implementations for different
* platform versions.
*
* @param context Context to initialize config-dependent params from
* @param forParent Parent view to monitor
*/
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
if (forParent == null) {
throw new IllegalArgumentException("Parent view may not be null");
}
if (cb == null) {
throw new IllegalArgumentException("Callback may not be null");
}
mParentView = forParent;
mCallback = cb;
final ViewConfiguration vc = ViewConfiguration.get(context);
final float density = context.getResources().getDisplayMetrics().density;
mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);
mTouchSlop = vc.getScaledTouchSlop();
mMaxVelocity = vc.getScaledMaximumFlingVelocity();
mMinVelocity = vc.getScaledMinimumFlingVelocity();
mScroller = ScrollerCompat.create(context, sInterpolator);
}
/**
* Set the minimum velocity that will be detected as having a magnitude greater than zero
* in pixels per second. Callback methods accepting a velocity will be clamped appropriately.View on GitHub (pinned to 3de8d90593)
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.
Example fix
// before
@Override protected void onCreate(Bundle b) {
super.onCreate(b);
mHelper = ViewDragHelper.create(this, (ViewGroup) findViewById(R.id.container), mCallback); // null before setContentView
setContentView(R.layout.main);
}
// after
@Override protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
ViewGroup parent = (ViewGroup) findViewById(R.id.container);
if (parent != null) {
mHelper = ViewDragHelper.create(this, parent, mCallback);
}
} Defensive patterns
Strategy: validation
Validate before calling
View parent = findViewById(R.id.drag_container);
if (parent instanceof ViewGroup) {
mHelper = ViewDragHelper.create(this, (ViewGroup) parent, mCallback);
} else {
Log.e(TAG, "drag_container missing in this layout");
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Callback may not be null
- captureChildView: parameter must be a descendant of the View
- Cannot settleCapturedViewAt outside of a call to Callback#on
- Cannot flingCapturedView outside of a call to Callback#onVie
- You can't set adapter to DialogsList. Use #setAdapter(Dialog
AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22).
Data as JSON: /api/errors/de5e9e2222431819.
Report an issue: GitHub.