{"record":{"id":"0e58f9eaebca7585","repo":"umano/AndroidSlidingUpPanel","slug":"cannot-flingcapturedview-outside-of-a-call-to-call","errorCode":null,"errorMessage":"Cannot flingCapturedView outside of a call to Callback#onViewReleased","messagePattern":"Cannot flingCapturedView outside of a call to Callback#onViewReleased","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java","lineNumber":722,"sourceCode":"    private float distanceInfluenceForSnapDuration(float f) {\n        f -= 0.5f; // center the values about 0.\n        f *= 0.3f * Math.PI / 2.0f;\n        return (float) Math.sin(f);\n    }\n\n    /**\n     * Settle the captured view based on standard free-moving fling behavior.\n     * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame\n     * to continue the motion until it returns false.\n     *\n     * @param minLeft Minimum X position for the view's left edge\n     * @param minTop Minimum Y position for the view's top edge\n     * @param maxLeft Maximum X position for the view's left edge\n     * @param maxTop Maximum Y position for the view's top edge\n     */\n    public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {\n        if (!mReleaseInProgress) {\n            throw new IllegalStateException(\"Cannot flingCapturedView outside of a call to \" +\n                    \"Callback#onViewReleased\");\n        }\n\n        mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),\n                (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),\n                (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),\n                minLeft, maxLeft, minTop, maxTop);\n\n        setDragState(STATE_SETTLING);\n    }\n\n    /**\n     * Move the captured settling view by the appropriate amount for the current time.\n     * If <code>continueSettling</code> returns true, the caller should call it again\n     * on the next frame to continue.\n     *\n     * @param deferCallbacks true if state callbacks should be deferred via posted message.\n     *                       Set this to true if you are calling this method from","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java#L704-L740","documentation":"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.","triggerScenarios":"Calling flingCapturedView from touch handlers, computeScroll, or after the release finished — anywhere except within onViewReleased.","commonSituations":"Implementing fling behavior but hooking it into onInterceptTouchEvent or a button click; copying fling code out of onViewReleased during refactoring.","solutions":["Call flingCapturedView only inside onViewReleased","For non-release flings, compute velocity yourself and use forceSettleCapturedViewAt or smoothSlideViewTo","Keep fling bounds computation inside the release callback"],"exampleFix":"// before\n@Override public void onViewCaptured(View child, int id) {\n    mDragHelper.flingCapturedView(minL, minT, maxL, maxT);\n}\n// after\n@Override public void onViewReleased(View child, float xvel, float yvel) {\n    mDragHelper.flingCapturedView(minL, minT, maxL, maxT);\n}","handlingStrategy":"validation","validationCode":"@Override\npublic void onViewReleased(View child, float xvel, float yvel) {\n    if (Math.abs(xvel) > minFling) {\n        mDragHelper.flingCapturedView(minL, minT, maxL, maxT);\n    } else {\n        mDragHelper.settleCapturedViewAt(targetLeft, targetTop);\n    }\n    ViewCompat.postInvalidateOnAnimation(container);\n}","typeGuard":null,"tryCatchPattern":"try { mDragHelper.flingCapturedView(l, t, r, b); } catch (IllegalStateException e) { mDragHelper.settleCapturedViewAt(targetL, targetT); }","preventionTips":["Call only inside onViewReleased","Trigger invalidation after fling (postInvalidateOnAnimation)","Keep fling bounds computed before release"],"tags":["android","viewdraghelper","invalid-state","fling"],"backgroundTag":"invalid-state-transition","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}