sergejsha / pinned-section-listview

Easy to use ListView with pinned sections for Android.
2.59k stars 808 forks source link

NullPointerException #33

Closed PaNaVTEC closed 10 years ago

PaNaVTEC commented 10 years ago

I have this while scrolling, The previous line: View nextSectionView = getChildAt(nextSectionPosition - firstVisibleItem); nextSectionPosition - firstVisibleItem gives -1 so nextSectionView is null.

12-22 11:16:50.378  18806-18806/bakingcode.tweedb E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at com.hb.views.PinnedSectionListView.ensureShadowForPosition(PinnedSectionListView.java:261)
            at com.hb.views.PinnedSectionListView$1.onScroll(PinnedSectionListView.java:122)
            at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1391)
            at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5399)
            at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3242)
            at android.widget.AbsListView.onTouchEvent(AbsListView.java:3690)
            at android.view.View.dispatchTouchEvent(View.java:7384)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2202)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1937)
            at com.hb.views.PinnedSectionListView.dispatchTouchEvent(PinnedSectionListView.java:466)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2184)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1614)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2497)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2132)
            at android.view.View.dispatchPointerEvent(View.java:7564)
            at android.view.ViewRootImpl$1.doDispatch(ViewRootImpl.java:354)
            at com.lge.view.TouchEventFilter.dispatchFilteredTouchEvent(TouchEventFilter.java:132)
            at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3368)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3271)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4501)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4480)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4581)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
            at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
            at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
            at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4551)
            at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4600)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
            at android.view.Choreographer.doCallbacks(Choreographer.java:562)
            at android.view.Choreographer.doFrame(Choreographer.java:530)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5171)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564)```
PaNaVTEC commented 10 years ago

I debugged and this bug is an error about my SectionIndexer, but I think the listview should be protected against NullPointer. Close it if you want.

timgreen commented 10 years ago

Another case for SectionIndexer caused the problem, just for someone else may have the same problem.

In some device, after update data in adapter. SectionIndexer.getSections will not the invoke again. If your implementation of getPositionForSection is base on some cache generated in getSections, then here is the problem.

One workaround can be found here: http://stackoverflow.com/questions/11638551/android-fastscrolling-sectionindexer-getsections-is-called-only-once