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());
AppBarLayout
and just avoid streaming null motion events to the super implementation inonInterceptTouchEvent
method, until google releases fix for this. – Nikola Despotoski