umano/AndroidSlidingUpPanel · error · java.lang.IllegalStateException

Cannot flingCapturedView outside of a call to…

Error message

Cannot flingCapturedView outside of a call to Callback#onViewReleased

What it means

flingCapturedView() is likewise restricted to Callback.onViewReleased(); it needs the release-time velocity tracker which is only valid while mReleaseInProgress is true. Outside that window it throws IllegalStateException.

Solutions

  1. Call flingCapturedView only inside onViewReleased
  2. For non-release flings, compute velocity yourself and use forceSettleCapturedViewAt or smoothSlideViewTo
  3. Keep fling bounds computation inside the release callback

Example fix

// before
@Override public void onViewCaptured(View child, int id) {
    mDragHelper.flingCapturedView(minL, minT, maxL, maxT);
}
// after
@Override public void onViewReleased(View child, float xvel, float yvel) {
    mDragHelper.flingCapturedView(minL, minT, maxL, maxT);
}
Defensive patterns

Strategy: validation

Validate before calling

@Override
public void onViewReleased(View child, float xvel, float yvel) {
    if (Math.abs(xvel) > minFling) {
        mDragHelper.flingCapturedView(minL, minT, maxL, maxT);
    } else {
        mDragHelper.settleCapturedViewAt(targetLeft, targetTop);
    }
    ViewCompat.postInvalidateOnAnimation(container);
}

Try / catch

try { mDragHelper.flingCapturedView(l, t, r, b); } catch (IllegalStateException e) { mDragHelper.settleCapturedViewAt(targetL, targetT); }

Prevention

When it happens

Trigger: Calling flingCapturedView from touch handlers, computeScroll, or after the release finished — anywhere except within onViewReleased.

Common situations: Implementing fling behavior but hooking it into onInterceptTouchEvent or a button click; copying fling code out of onViewReleased during refactoring.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of umano/AndroidSlidingUpPanel@45a460435b (2026-09-11). Data as JSON: /api/errors/0e58f9eaebca7585. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java:722

    private float distanceInfluenceForSnapDuration(float f) {
        f -= 0.5f; // center the values about 0.
        f *= 0.3f * Math.PI / 2.0f;
        return (float) Math.sin(f);
    }

    /**
     * Settle the captured view based on standard free-moving fling behavior.
     * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame
     * to continue the motion until it returns false.
     *
     * @param minLeft Minimum X position for the view's left edge
     * @param minTop Minimum Y position for the view's top edge
     * @param maxLeft Maximum X position for the view's left edge
     * @param maxTop Maximum Y position for the view's top edge
     */
    public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
        if (!mReleaseInProgress) {
            throw new IllegalStateException("Cannot flingCapturedView outside of a call to " +
                    "Callback#onViewReleased");
        }

        mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
                (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
                (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
                minLeft, maxLeft, minTop, maxTop);

        setDragState(STATE_SETTLING);
    }

    /**
     * Move the captured settling view by the appropriate amount for the current time.
     * If <code>continueSettling</code> returns true, the caller should call it again
     * on the next frame to continue.
     *
     * @param deferCallbacks true if state callbacks should be deferred via posted message.
     *                       Set this to true if you are calling this method from

View on GitHub (pinned to 45a460435b)