{"record":{"id":"e605680c367ac01a","repo":"daimajia/AndroidSwipeLayout","slug":"can-not-find-swipelayout-in-target-view","errorCode":null,"errorMessage":"can not find SwipeLayout in target view","messagePattern":"can not find SwipeLayout in target view","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java","lineNumber":54,"sourceCode":"        this.swipeAdapterInterface = swipeAdapterInterface;\n    }\n\n    public Attributes.Mode getMode() {\n        return mode;\n    }\n\n    public void setMode(Attributes.Mode mode) {\n        this.mode = mode;\n        mOpenPositions.clear();\n        mShownLayouts.clear();\n        mOpenPosition = INVALID_POSITION;\n    }\n\n    public void bind(View view, int position) {\n        int resId = swipeAdapterInterface.getSwipeLayoutResourceId(position);\n        SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(resId);\n        if (swipeLayout == null)\n            throw new IllegalStateException(\"can not find SwipeLayout in target view\");\n\n        if (swipeLayout.getTag(resId) == null) {\n            OnLayoutListener onLayoutListener = new OnLayoutListener(position);\n            SwipeMemory swipeMemory = new SwipeMemory(position);\n            swipeLayout.addSwipeListener(swipeMemory);\n            swipeLayout.addOnLayoutListener(onLayoutListener);\n            swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));\n            mShownLayouts.add(swipeLayout);\n        } else {\n            ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);\n            valueBox.swipeMemory.setPosition(position);\n            valueBox.onLayoutListener.setPosition(position);\n            valueBox.position = position;\n        }\n    }\n\n    @Override\n    public void openItem(int position) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/daimajia/AndroidSwipeLayout/blob/5f8678b04751fb8510a88586b22e07ccf64bca99/library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure getSwipeLayoutResourceId(position) returns the R.id of a SwipeLayout actually present in the inflated item layout","Verify getLayoutId inflates the layout that contains that SwipeLayout id","Check bind is called with the item root view (convertView) and correct view type","Rebuild the project so R.id constants match the current XML"],"exampleFix":"// before\n@Override\npublic int getSwipeLayoutResourceId(int position) {\n    return R.id.swipe; // no such id in item layout\n}\n// after\n@Override\npublic int getSwipeLayoutResourceId(int position) {\n    return R.id.swipe_layout; // matches <com.daimajia.swipe.SwipeLayout android:id=\"@+id/swipe_layout\"/> in item_swipe.xml\n}","handlingStrategy":"validation","validationCode":"int resId = adapter.getSwipeLayoutResourceId(position);\nif (itemView.findViewById(resId) == null || !(itemView.findViewById(resId) instanceof SwipeLayout)) {\n    throw new IllegalStateException(\"item view is missing SwipeLayout with id \" + resId);\n}\nadapter.getItemManager().bind(itemView, position);","typeGuard":"boolean hasSwipeLayout(View itemView, int resId) {\n    return itemView.findViewById(resId) instanceof SwipeLayout;\n}","tryCatchPattern":"try {\n    mItemManger.bind(convertView, position);\n} catch (IllegalStateException e) {\n    Log.e(TAG, \"bind failed: SwipeLayout missing in item view for position \" + position, e);\n}","preventionTips":["Keep getSwipeLayoutResourceId and the inflated item layout XML in sync","Always inflate the layout that contains the SwipeLayout in getView/bindView","Use the @+id declared on the com.daimajia.swipe.SwipeLayout element itself, not a wrapper view","Rebuild after XML id renames so R.id stays consistent"],"tags":["android","adapter","view-binding","illegal-state"],"backgroundTag":"entity-not-found","analyzedSha":"5f8678b04751fb8510a88586b22e07ccf64bca99","analyzedAt":"2026-09-08T03:35:37.231Z","contentChangedAt":"2026-09-08T03:35:37.231Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}