我有一个问题,一个奇怪的问题,我无法复制,但是我看到很多用户都存在该问题。坠机事故由Crashlitycs捕获。问题是:
致命异常:java.lang.NullPointerException
尝试在空对象引用上调用虚拟方法'int android.support.v4.widget.ViewDragHelper.getTouchSlop()'
目前,我已将支持库设置为28.0.0。
我不知道下一步该怎么做,因为我不知道此错误来自何处,并且无法复制它
final SUPPORT_LIBRARY_VERSION = '28.0.0'
// Support
implementation "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation "com.android.support:exifinterface:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:support-media-compat:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
这是我的Logcat
at android.support.design.widget.BottomSheetBehavior.onTouchEvent(BottomSheetBehavior.java:350)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:476)
at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:527)
at android.view.View.dispatchTouchEvent(View.java:9390)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2461)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1777)
at android.app.Activity.dispatchTouchEvent(Activity.java:2865)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2422)
at android.view.View.dispatchPointerEvent(View.java:9610)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4447)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4313)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4049)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6146)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6120)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6081)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6262)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:330)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
--
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.support.v4.widget.ViewDragHelper.getTouchSlop()' on a null object reference
at android.support.design.widget.BottomSheetBehavior.onTouchEvent(BottomSheetBehavior.java:350)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:476)
at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:527)
at android.view.View.dispatchTouchEvent(View.java:9390)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2461)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1777)
at android.app.Activity.dispatchTouchEvent(Activity.java:2865)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2422)
at android.view.View.dispatchPointerEvent(View.java:9610)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4447)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4313)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4049)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6146)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6120)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6081)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6262)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:330)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
#0. Crashed: main
at android.support.design.widget.BottomSheetBehavior.onTouchEvent(BottomSheetBehavior.java:350)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:476)
at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:527)
at android.view.View.dispatchTouchEvent(View.java:9390)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2461)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1777)
at android.app.Activity.dispatchTouchEvent(Activity.java:2865)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2422)
at android.view.View.dispatchPointerEvent(View.java:9610)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4447)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4313)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4049)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3900)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3866)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3874)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3847)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6146)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6120)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6081)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6262)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:330)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
目前,我将
BottomSheetDialogFragment
扩展为很多片段(嗯,几乎所有片段) 最佳答案
在源代码中返回用于读取的行:
return action == MotionEvent.ACTION_MOVE
&& scroll != null
&& !ignoreEvents
&& state != STATE_DRAGGING
&& !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
&& Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
}
似乎在以后的版本中可供阅读:
return action == MotionEvent.ACTION_MOVE
&& scroll != null
&& !ignoreEvents
&& state != STATE_DRAGGING
&& !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
&& viewDragHelper != null
&& Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
}
似乎应该将其修复。尽管其他一些功能似乎清除了viewDragHelper的值,所以通常很难复制它。
在某些版本中,如果在调用onLayoutChild()之前执行了触摸移动,则可能会出现空指针错误。似乎很难做到。但是,没有明确检查。
显然,它应该是固定的,但是我没有在源文件中看到任何明确的检查,并且它们的复制步骤仍然可以为您提供帮助。
https://github.com/material-components/material-components-android/issues/43
“这可以通过将触摸事件发送至垃圾邮件来在较旧/较慢的设备上发生
底层,而布局正在构建中。”