NPE In BottomSheetBehaviour.onInterceptTouchEvent
See original GitHub issueOverview
NullPointerException when attempting to delegate onInterceptTouchEvents
to a BottomSheet
before onLayoutChild
has been called.
The view reference is not checked before being interacted with, which the MotionEvent.ACTION_DOWN
case is doing.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.Reference.get()' on a null object reference
at android.support.design.widget.BottomSheetBehavior.onInterceptTouchEvent(BottomSheetBehavior.java:299)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:460)
at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:499)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2402)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2492)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2492)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2492)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2492)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2492)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:505)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1863)
at android.app.Activity.dispatchTouchEvent(Activity.java:3226)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:467)
at android.view.View.dispatchPointerEvent(View.java:10954)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5051)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4908)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4492)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4458)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4591)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4648)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4492)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4458)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6936)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6875)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6836)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7046)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Reproduction steps
This can occur on older/slower devices by spamming touch events to the bottom sheet whilst the layout is being constructed.
Version number
- 26.1.0
Operating system and device
Am able to consistently reproduce on a Samsung S7 7.0. Was originally reported via crashyltics on Samsung Galaxy J1 4.4.4 and Oppo A37fw 5.1.1
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top Results From Across the Web
android - NullPointerException with AppCompat BottomSheets
The solution is to provide our own class which extends BottomSheetBehavior, but setting the state inside an overridden onLayoutChild.
Read more >Bug: bottomSheet heights aren't flexible enough [37086569]
NullPointerException : Attempt to invoke virtual method 'int android.view.MotionEvent. ... onInterceptTouchEvent(BottomSheetBehavior.java:216)
Read more >com.google.android.material.bottomsheet.BottomSheetBehavior
Best Java code snippets using com.google.android.material.bottomsheet.BottomSheetBehavior.onInterceptTouchEvent (Showing top 1 results out of 315).
Read more >vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior ...
public class BottomSheetBehavior<V extends View> extends ... public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {.
Read more >该视图与bottomsheetbehavior android无关 - 免费编程教程
Bottomsheet 行为onintercepttouchevent ... NPE In BottomSheetBehaviour.onInterceptTouchEvent · 问题#43 , CoordinatorLayout 的子视图的交互行为插件,可使其作为 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There’s another issue related to this, we’re seeing onStopNestedScroll get called before the view is laid out. However there’s a block in this method where
setStateInternal
can get called. That’s what’s happening for us.Then in
setStateInternal
, this line causes a crash:View bottomSheet = viewRef.get();
Because viewRef hasn’t been assigned
We’re seeing a huge influx of these NPEs. We’re using version 28.0.0 as well and have many bottom sheets in the app so it’s pretty hard to know where it’s coming from:
Is anyone else seeing this?