{"record":{"id":"ad7d81f11f7a29f2","repo":"material-components/material-components-android","slug":"no-revealablelistitem-with-gravity","errorCode":null,"errorMessage":"No RevealableListItem with gravity {}","messagePattern":"No RevealableListItem with gravity (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/listitem/ListItemLayout.java","lineNumber":691,"sourceCode":"    return getLayoutDirection() == LAYOUT_DIRECTION_RTL ? Gravity.LEFT : Gravity.RIGHT;\n  }\n\n  private boolean swipeToRevealLayoutExistsForGravity(@RevealGravity int gravity) {\n    // Make sure the reveal layouts are associated with the correct gravities, in case there are any\n    // swaps.\n    maybeSwapRevealLayoutsForGravity();\n\n    if (isRevealGravityLeft(gravity)) {\n      return swipeToRevealLayoutLeft instanceof RevealableListItem;\n    } else {\n      return swipeToRevealLayoutRight instanceof RevealableListItem;\n    }\n  }\n\n  private int getOffsetForSwipeState(\n      @StableSwipeState int swipeState, @RevealGravity int revealGravity) {\n    if (!swipeToRevealLayoutExistsForGravity(revealGravity)) {\n      throw new IllegalArgumentException(\"No RevealableListItem with gravity \" + revealGravity);\n    }\n    switch (swipeState) {\n      case STATE_CLOSED:\n        return getSwipeViewClosedOffset();\n      case STATE_OPEN:\n        return getSwipeRevealViewRevealedOffset(revealGravity);\n      case STATE_SWIPE_PRIMARY_ACTION:\n        return getSwipeToActionOffset(revealGravity);\n      default:\n        throw new IllegalArgumentException(\"Invalid state to get swipe offset: \" + swipeState);\n    }\n  }\n\n  private void updateSwipeProgress(int left) {\n    if (!(contentView instanceof SwipeableListItem && swipeToRevealLayoutExists())) {\n      return;\n    }\n    revealViewOffset = left - originalContentViewLeft;","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/listitem/ListItemLayout.java#L673-L709","documentation":"getOffsetForSwipeState(swipeState, revealGravity) first requires that a RevealableListItem exists for the requested reveal gravity (start or end). It is an internal calculation for where the content view should sit; calling it for a gravity that has no reveal layout has no meaningful offset, so it throws IllegalArgumentException echoing the missing gravity value.","triggerScenarios":"setSwipeState(STATE_OPEN/STATE_SWIPE_PRIMARY_ACTION, REVEAL_GRAVITY_START, ...) on a ListItemLayout that only has an end-gravity RevealableListItem; computing offsets via reflection or subclass code with a gravity the layout does not provide.","commonSituations":"Supporting both swipe directions in code while the XML only defines a reveal view on one side; RTL layouts where the expected gravity constant differs from what the layout actually holds.","solutions":["Before requesting a state for a gravity, add a RevealableListItem child with that gravity (start and/or end) to the ListItemLayout.","If only one reveal side exists, always pass that side's gravity to setSwipeState.","In RTL-aware code, resolve gravity from the reveal view's LayoutParams rather than a hardcoded constant."],"exampleFix":"// before\nlistItemLayout.setSwipeState(\n    ListItemLayout.STATE_OPEN, REVEAL_GRAVITY_START, true);\n// layout only defines an end-gravity reveal -> throws\n\n// after\nint gravity = ((ListItemLayout.LayoutParams) revealView.getLayoutParams()).gravity;\nlistItemLayout.setSwipeState(ListItemLayout.STATE_OPEN, gravity, true);","handlingStrategy":"validation","validationCode":"boolean startExists = listItemLayout.findViewById(R.id.reveal_start) != null;\nboolean endExists = listItemLayout.findViewById(R.id.reveal_end) != null;\nint gravity = startExists ? ListItemLayout.REVEAL_GRAVITY_START : ListItemLayout.REVEAL_GRAVITY_END;\nif (!startExists && !endExists) throw new IllegalStateException(\"No reveal children defined\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive gravity from the reveal view actually present in the layout.","Define reveal children for any gravity you will programmatically target.","In RTL, resolve gravity from LayoutParams instead of constants."],"tags":["material-components","listitem","swipe","gravity"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}