Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoordinatorLayout NullPointerException in onTouchEvent

I am getting NullPointerException in onTouchEvent of CoordinatorLayout.

I am using DrawerLayout with CollapsingToolbarLayout of android support AppCompat v23.0.0 library.

My observation is crash happen randomly while scrolling CollapsingToolbarLayout or click on drawer items.

Is there anyone facing this issue? any work around to avoid this exception?

Logcat:

08-22 15:16:34.657: E/AndroidRuntime(27596): java.lang.NullPointerException: Attempt to invoke virtual method 'float android.view.MotionEvent.getX()' on a null object reference
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.view.View.onTouchEvent(View.java:9321)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:449)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.view.View.dispatchTouchEvent(View.java:8388)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2398)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.support.v4.widget.DrawerLayout.cancelChildViewTouch(DrawerLayout.java:1491)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.support.v4.widget.DrawerLayout$ViewDragCallback.peekDrawer(DrawerLayout.java:1739)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.support.v4.widget.DrawerLayout$ViewDragCallback.access$000(DrawerLayout.java:1624)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.support.v4.widget.DrawerLayout$ViewDragCallback$1.run(DrawerLayout.java:1630)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.os.Handler.handleCallback(Handler.java:739)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.os.Handler.dispatchMessage(Handler.java:95)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.os.Looper.loop(Looper.java:135)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at android.app.ActivityThread.main(ActivityThread.java:5221)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at java.lang.reflect.Method.invoke(Native Method)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at java.lang.reflect.Method.invoke(Method.java:372)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
08-22 15:16:34.657: E/AndroidRuntime(27596):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
08-22 15:16:35.965: I/Process(27596): Sending signal. PID: 27596 SIG: 9
like image 660
Priyank Patel Avatar asked Aug 22 '15 10:08

Priyank Patel


2 Answers

This works for me. https://code.google.com/p/android/issues/detail?id=183166

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    try {
        return super.dispatchTouchEvent(ev);
    } catch (Exception e) {
        return false;
    }
}
like image 81
Kevin Salazar Avatar answered Oct 18 '22 21:10

Kevin Salazar


According to the link posed by Kevin Salazar, the bug is fixed if you update your support library to version 23.0.1

like image 9
davidchuyaya Avatar answered Oct 18 '22 22:10

davidchuyaya