question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NPE In BottomSheetBehaviour.onInterceptTouchEvent

See original GitHub issue

Overview

NullPointerException when attempting to delegate onInterceptTouchEvents to a BottomSheet before onLayoutChild has been called.

https://github.com/material-components/material-components-android/blob/master/lib/src/android/support/design/widget/BottomSheetBehavior.java#L281

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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JayyyRcommented, Mar 4, 2019

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

0reactions
yoavgraycommented, Oct 29, 2020

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:

java.lang.NullPointerException: Attempt to invoke virtual method 'int androidx.customview.widget.ViewDragHelper.getTouchSlop()' on a null object reference
	at com.google.android.material.bottomsheet.BottomSheetBehavior.onTouchEvent(BottomSheetBehavior.java:350)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:476)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:527)
	at android.view.View.dispatchTouchEvent(View.java:13473)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3216)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2888)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2904)
	at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:742)
	at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1880)
	at android.app.Activity.dispatchTouchEvent(Activity.java:3494)
	at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
	at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:700)
	at android.view.View.dispatchPointerEvent(View.java:13721)
	at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6175)
	at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5953)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5402)
	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5455)
	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5421)
	at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5580)
	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5429)
	at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5637)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5402)
	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5455)
	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5421)
	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5429)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5402)
	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8467)
	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8387)
	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8340)
	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8582)
	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:198)
	at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
	at android.os.MessageQueue.next(MessageQueue.java:326)
	at android.os.Looper.loop(Looper.java:181)
	at android.app.ActivityThread.main(ActivityThread.java:7094)
	at java.lang.reflect.Method.invoke(Method.java)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Is anyone else seeing this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found