umano/AndroidSlidingUpPanel · error · java.lang.IllegalArgumentException
Parent view may not be null
Error message
Parent view may not be null
What it means
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.
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
Example fix
// before mDragHelper = ViewDragHelper.create((ViewGroup) getParent(), callback); // after mDragHelper = ViewDragHelper.create(this, callback); // inside the custom ViewGroup
Defensive patterns
Strategy: type-guard
Validate before calling
ViewGroup parent = (parentView != null) ? parentView : this; mDragHelper = ViewDragHelper.create(parent, sensitivity, callback);
Type guard
ViewGroup safeParent(ViewGroup v) { return v != null ? v : (ViewGroup) requireNotNull(getParent(), "not attached yet"); } Prevention
- Pass 'this' from the custom ViewGroup, not getParent()
- Create the helper in onAttachedToWindow if parent needed
- Never create helper before view inflation
When it happens
Trigger: 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.
Common situations: Constructing the helper in a custom View's field initializer before the parent exists, or passing a detached view's null parent.
Related errors
- Callback may not be null
- captureChildView: parameter must be a descendant of the…
- Cannot settleCapturedViewAt outside of a call to…
- Cannot flingCapturedView outside of a call to…
- gravity must be set to either top or bottom
AI-assisted analysis of umano/AndroidSlidingUpPanel@45a460435b (2026-09-11).
Data as JSON: /api/errors/6421b468ba8d2d52.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java:406
public static ViewDragHelper create(ViewGroup forParent, float sensitivity, Interpolator interpolator, Callback cb) {
final ViewDragHelper helper = create(forParent, interpolator, 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.
* If the interpolator is null, the default interpolator will be used.
*
* @param context Context to initialize config-dependent params from
* @param forParent Parent view to monitor
* @param interpolator interpolator for scroller
*/
private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interpolator, 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, interpolator != null ? interpolator : sInterpolator);
}
View on GitHub (pinned to 45a460435b)