Android的小吃店崩溃与设计支持库23.0.0触摸 [英] Android SnackBar crashes on touch with design support library 23.0.0
问题描述
升级到设计支持库23.0.0和建立SDK 23,我的应用程序崩溃,当我试图驳回小吃吧后
:
显示java.lang.NullPointerException:尝试调用虚拟方法INT android.view.MotionEvent.getAction()'对空对象引用
在android.support.design.widget.AppBarLayout $ Behavior.onInterceptTouchEvent(AppBarLayout.java:729)
在android.support.design.widget.AppBarLayout $ Behavior.onInterceptTouchEvent(AppBarLayout.java:629)
在android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:357)
在android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:409)
由于更新我并没有改变任何东西,我使用的唯一途径,我知道关闭显示小吃吧:
Snackbar.make(rootView,的getString(R.string.error_no_permissions),Snackbar.LENGTH_LONG).show();
目前在 CoordinatorLayout
报道了NPE的问题可能有关:的 CoordinatorLayout NullPointerException异常中的onTouchEvent ,但我仍然无法找到一个解决方法我的情况。我已经试过这可能的解决方案但仍然没有运气...
编辑:
原来的解决方案是(作为@NikolaDespotoski建议)覆盖默认 AppBarLayout.Behavior
公共类AppBarLayoutBehavior扩展AppBarLayout.Behavior {
@覆盖
公共布尔onInterceptTouchEvent(CoordinatorLayout父母,AppBarLayout孩子,
MotionEvent EV){
返回!(父= NULL和放大器;!&安培;童= NULL和放大器;!&安培; EV!= NULL)||超
.onInterceptTouchEvent(父母,子女,EV);
}
}
......,并用它在我们的 AppBarLayout
((CoordinatorLayout.LayoutParams)findViewById(R.id.appbar).getLayoutParams())
.setBehavior(新AppBarLayoutBehavior());
暂时被覆盖 onInterceptTouchEvent
的另一个固定的 AppBarLayout.Behavior
和无效的或空 MotionEvent
被丢弃,只是为了减轻超级实施崩溃。
这将回荡为:
@覆盖
公共布尔onInterceptTouchEvent(CoordinatorLayout父母,AppBarLayout孩子,MotionEvent EV){
返回EV!= NULL? super.onInterceptTouchEvent(父母,子女,EV):真正的;
}
对于 MotionEvent
这可能是无效的,我们不会做任何事情,所以我们做了继承行为
认为,我们已经处理了。
After upgrading to Design Support Library 23.0.0 and build SDK 23, my application crashes when I try to dismiss a Snackbar
:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.MotionEvent.getAction()' on a null object reference
at android.support.design.widget.AppBarLayout$Behavior.onInterceptTouchEvent(AppBarLayout.java:729)
at android.support.design.widget.AppBarLayout$Behavior.onInterceptTouchEvent(AppBarLayout.java:629)
at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:357)
at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:409)
I haven't changed anything since the update and I use the only way that I know off for showing a Snackbar:
Snackbar.make(rootView, getString(R.string.error_no_permissions),Snackbar.LENGTH_LONG).show();
There is an issue reported for NPE on CoordinatorLayout
that could be related: CoordinatorLayout NullPointerException in onTouchEvent but I still can't find a workaround for my situation. I've tried this possible solution but still no luck...
EDIT:
Turns out the solution is (as @NikolaDespotoski suggested) overriding the default AppBarLayout.Behavior
public class AppBarLayoutBehavior extends AppBarLayout.Behavior {
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child,
MotionEvent ev) {
return !(parent != null && child != null && ev != null) || super
.onInterceptTouchEvent(parent, child, ev);
}
}
...and use it in our AppBarLayout
((CoordinatorLayout.LayoutParams) findViewById(R.id.appbar).getLayoutParams())
.setBehavior(new AppBarLayoutBehavior());
Another fix for the time being is overriding onInterceptTouchEvent
of the AppBarLayout.Behavior
and invalid or null MotionEvent
being discarded, just to mitigate the crash in the super implementation.
That would resound as:
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev){
return ev != null ? super.onInterceptTouchEvent(parent,child, ev) : true;
}
For the MotionEvent
that was probably invalid, we won't do anything about it, so we make the inherited Behavior
thinks we have handled it.
这篇关于Android的小吃店崩溃与设计支持库23.0.0触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!