daimajia/AndroidSwipeLayout · error · IllegalStateException

can not find SwipeLayout in target view

Error message

can not find SwipeLayout in target view

What it means

SwipeItemMangerImpl.bind(view, position) reads the swipe layout resource id from the adapter and looks it up inside the given item view via findViewById. If no SwipeLayout with that id exists in the item view, it throws IllegalStateException because it cannot bind swipe listeners for that position.

Solutions

  1. Ensure getSwipeLayoutResourceId(position) returns the R.id of a SwipeLayout actually present in the inflated item layout
  2. Verify getLayoutId inflates the layout that contains that SwipeLayout id
  3. Check bind is called with the item root view (convertView) and correct view type
  4. Rebuild the project so R.id constants match the current XML

Example fix

// before
@Override
public int getSwipeLayoutResourceId(int position) {
    return R.id.swipe; // no such id in item layout
}
// after
@Override
public int getSwipeLayoutResourceId(int position) {
    return R.id.swipe_layout; // matches <com.daimajia.swipe.SwipeLayout android:id="@+id/swipe_layout"/> in item_swipe.xml
}
Defensive patterns

Strategy: validation

Validate before calling

int resId = adapter.getSwipeLayoutResourceId(position);
if (itemView.findViewById(resId) == null || !(itemView.findViewById(resId) instanceof SwipeLayout)) {
    throw new IllegalStateException("item view is missing SwipeLayout with id " + resId);
}
adapter.getItemManager().bind(itemView, position);

Type guard

boolean hasSwipeLayout(View itemView, int resId) {
    return itemView.findViewById(resId) instanceof SwipeLayout;
}

Try / catch

try {
    mItemManger.bind(convertView, position);
} catch (IllegalStateException e) {
    Log.e(TAG, "bind failed: SwipeLayout missing in item view for position " + position, e);
}

Prevention

When it happens

Trigger: getSwipeLayoutResourceId(position) returns an id that does not correspond to a SwipeLayout inside the converted item view, e.g. wrong layout inflated for the item, mismatched R.id, or the view root passed to bind is not the item layout.

Common situations: Adapter's getLayoutId and getSwipeLayoutResourceId point to different layouts; converter view of another item type is passed to bind; layout refactor removed/renamed the SwipeLayout id; findViewById returns null because the id lives in a header/other view.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of daimajia/AndroidSwipeLayout@5f8678b047 (2026-09-08). Data as JSON: /api/errors/e605680c367ac01a. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java:54

        this.swipeAdapterInterface = swipeAdapterInterface;
    }

    public Attributes.Mode getMode() {
        return mode;
    }

    public void setMode(Attributes.Mode mode) {
        this.mode = mode;
        mOpenPositions.clear();
        mShownLayouts.clear();
        mOpenPosition = INVALID_POSITION;
    }

    public void bind(View view, int position) {
        int resId = swipeAdapterInterface.getSwipeLayoutResourceId(position);
        SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(resId);
        if (swipeLayout == null)
            throw new IllegalStateException("can not find SwipeLayout in target view");

        if (swipeLayout.getTag(resId) == null) {
            OnLayoutListener onLayoutListener = new OnLayoutListener(position);
            SwipeMemory swipeMemory = new SwipeMemory(position);
            swipeLayout.addSwipeListener(swipeMemory);
            swipeLayout.addOnLayoutListener(onLayoutListener);
            swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
            mShownLayouts.add(swipeLayout);
        } else {
            ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
            valueBox.swipeMemory.setPosition(position);
            valueBox.onLayoutListener.setPosition(position);
            valueBox.position = position;
        }
    }

    @Override
    public void openItem(int position) {

View on GitHub (pinned to 5f8678b047)