Skip to content

NullPointerException when using EpoxyTouchHelper.initDragging #1187

@lordcodes

Description

@lordcodes

I had a working drag implementation that was working fine with Epoxy v4.5.0.

EpoxyTouchHelper.initDragging(bindingController)
            .withRecyclerView(recyclerView)
            .forVerticalList()
            .withTarget(CompactCellBinder::class.java)
            .andCallbacks(ReorderDragCallback(::onCellMoved, ::onMoveComplete))

After updating to Epoxy v4.6.1, I now get an NPE whenever you drag a view over another. There is code in EpoxyTouchHelperCallback that is performing a cast when the ViewHolder is null. It looks like this class was converted from Java to Kotlin in this Epoxy release.

java.lang.NullPointerException: null cannot be cast to non-null type com.airbnb.epoxy.EpoxyViewHolder
        at com.airbnb.epoxy.EpoxyTouchHelperCallback.chooseDropTarget(EpoxyTouchHelperCallback.kt:104)
        at com.airbnb.epoxy.EpoxyTouchHelperCallback.chooseDropTarget(EpoxyTouchHelperCallback.kt:88)
        at com.airbnb.epoxy.EpoxyTouchHelperCallback.chooseDropTarget(EpoxyTouchHelperCallback.kt:11)
        at androidx.recyclerview.widget.ItemTouchHelper.moveIfNecessary(ItemTouchHelper.java:877)
        at androidx.recyclerview.widget.ItemTouchHelper$2.onTouchEvent(ItemTouchHelper.java:389)
        at androidx.recyclerview.widget.RecyclerView.dispatchToOnItemTouchListeners(RecyclerView.java:3259)
        at androidx.recyclerview.widget.RecyclerView.onTouchEvent(RecyclerView.java:3421)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions