daimajia/AndroidSwipeLayout · error · IllegalArgumentException
SwipeAdapterInterface can not be null
Error message
SwipeAdapterInterface can not be null
What it means
SwipeItemMangerImpl's constructor requires a non-null SwipeAdapterInterface, which it delegates to for swipe layout resource ids and modes. Passing null leaves the manager unable to operate, so the constructor throws IllegalArgumentException immediately.
Solutions
- Pass the adapter itself (this) when constructing the manager inside a BaseSwipeAdapter subclass
- Ensure the adapter field is initialized before the manager is constructed
- Never pass null; construct the manager lazily after the adapter is available
Example fix
// before
class MyAdapter extends BaseSwipeAdapter {
SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(null);
}
// after
class MyAdapter extends BaseSwipeAdapter {
SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
} Defensive patterns
Strategy: validation
Validate before calling
if (adapter == null) {
throw new IllegalArgumentException("adapter must be initialized before creating SwipeItemMangerImpl");
}
SwipeItemMangerImpl manager = new SwipeItemMangerImpl(adapter); Try / catch
try {
this.mItemManger = new SwipeItemMangerImpl(this);
} catch (IllegalArgumentException e) {
Log.e(TAG, "SwipeItemMangerImpl requires a non-null adapter", e);
} Prevention
- Always construct the manager with 'this' inside BaseSwipeAdapter subclasses
- Avoid initializing manager fields before adapter dependencies are ready
- Add constructor-time null assertions in custom adapters
When it happens
Trigger: Constructing SwipeItemMangerImpl (directly or via a subclass like SwipeItemAdapterMangerImpl / BaseSwipeAdapter) with a null SwipeAdapterInterface argument, e.g. an uninitialized adapter field passed to the manager.
Common situations: Custom adapter sets up the manager in a field initializer before the adapter reference is ready; passing null in tests; subclass forgets to call super(adapter) with a real adapter.
Related errors
AI-assisted analysis of daimajia/AndroidSwipeLayout@5f8678b047 (2026-09-08).
Data as JSON: /api/errors/a55c43a4b944a93c.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java:34
/**
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
*/
public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
private Attributes.Mode mode = Attributes.Mode.Single;
public final int INVALID_POSITION = -1;
protected int mOpenPosition = INVALID_POSITION;
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
protected SwipeAdapterInterface swipeAdapterInterface;
public SwipeItemMangerImpl(SwipeAdapterInterface swipeAdapterInterface) {
if (swipeAdapterInterface == null)
throw new IllegalArgumentException("SwipeAdapterInterface can not be null");
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);View on GitHub (pinned to 5f8678b047)