每次尝试删除 listView 中的第一项(可见)时,我都需要帮助弄清楚为什么会出现 Null 指针异常。删除其他所有项目都可以正常工作,没有任何错误,但第一个项目一直失败。
这是代码:
private void deleteCurrentItem() {
ContextualUndoView contextualUndoView = (ContextualUndoView) mDismissView;
int position = getAbsListView().getPositionForView(contextualUndoView);
mDeleteItemCallback.deleteItem(position);
}
详细代码: http: //paste.org/66633
错误日志:
08-10 19:09:22.107: E/AndroidRuntime(973): FATAL EXCEPTION: main
08-10 19:09:22.107: E/AndroidRuntime(973): java.lang.NullPointerException
08-10 19:09:22.107: E/AndroidRuntime(973): at android.widget.AdapterView.getPositionForView(AdapterView.java:597)
08-10 19:09:22.107: E/AndroidRuntime(973): at com.haarman.listviewanimations.itemmanipulation.contextualundo.ContextualUndoAdapter$RemoveViewAnimatorListenerAdapter.deleteCurrentItem(ContextualUndoAdapter.java:205)
08-10 19:09:22.107: E/AndroidRuntime(973): at com.haarman.listviewanimations.itemmanipulation.contextualundo.ContextualUndoAdapter$RemoveViewAnimatorListenerAdapter.onAnimationEnd(ContextualUndoAdapter.java:193)
08-10 19:09:22.107: E/AndroidRuntime(973): at com.nineoldandroids.animation.ValueAnimator.endAnimation(ValueAnimator.java:1034)
08-10 19:09:22.107: E/AndroidRuntime(973): at com.nineoldandroids.animation.ValueAnimator.cancel(ValueAnimator.java:968)
08-10 19:09:22.107: E/AndroidRuntime(973): at com.haarman.listviewanimations.itemmanipulation.contextualundo.ContextualUndoAdapter$RecycleViewListener.onMovedToScrapHeap(ContextualUndoAdapter.java:276)
08-10 19:09:22.107: E/AndroidRuntime(973): at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6449)
08-10 19:09:22.107: E/AndroidRuntime(973): at android.widget.ListView.measureHeightOfChildren(ListView.java:1256)