Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

android - DrawerLayout - Exception dispatching input event

I recently started using the DrawerLayout in a new project about a week ago and it's all working fine. Apart from the odd times when swiping it in and out with my finger it'll crash.

If I use the ActionBar Up/Home MenuItem though, it'll work fine every time.

In LogCat i get two stacktraces that both seem to point to internal android places, so I don't quite know what to do to solve this.

I just tried creating a new application to see if it was something I was doing before that was causing this, but it happened in the new application too.

I created the new application with the Master/Detail Flow template in the "New Android Application" window, left everything as defaults and just changed activity_item_list.xml to have this inside it:

<android.support.v4.widget.DrawerLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/item_list"
        android:name="com.navdrawertest.ItemListFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        tools:context=".ItemListActivity"
        tools:layout="@android:layout/list_content" />

    <!-- Navigation Drawer -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#111" />
 </android.support.v4.widget.DrawerLayout>

The DrawerLayout shows and I can still drag it from the edge of the screen, but it still crashes in this test app.

Here are the stacktraces I see after dragging it with my finger:

07-26 09:29:45.574: E/InputEventReceiver(19085): Exception dispatching input event.
07-26 09:29:45.574: E/MessageQueue-JNI(19085): Exception in MessageQueue callback: handleReceiveCallback
07-26 09:29:45.584: E/MessageQueue-JNI(19085): java.lang.NullPointerException
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:840)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:866)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1852)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.View.dispatchPointerEvent(View.java:7564)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.os.MessageQueue.nativePollOnce(Native Method)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.os.MessageQueue.next(MessageQueue.java:132)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.os.Looper.loop(Looper.java:124)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at android.app.ActivityThread.main(ActivityThread.java:5103)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at java.lang.reflect.Method.invokeNative(Native Method)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at java.lang.reflect.Method.invoke(Method.java:525)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-26 09:29:45.584: E/MessageQueue-JNI(19085):  at dalvik.system.NativeStart.main(Native Method)
07-26 09:29:45.584: D/AndroidRuntime(19085): Shutting down VM
07-26 09:29:45.584: W/dalvikvm(19085): threadid=1: thread exiting with uncaught exception (group=0x41cbb700)
07-26 09:29:45.594: E/AndroidRuntime(19085): FATAL EXCEPTION: main
07-26 09:29:45.594: E/AndroidRuntime(19085): java.lang.NullPointerException
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:840)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:866)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1852)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.View.dispatchPointerEvent(View.java:7564)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.os.MessageQueue.nativePollOnce(Native Method)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at android.os.MessageQueue.next(MessageQueue.java:132)
07-26 09:29:45.594: E/AndroidRuntime(19085):    at androi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have also got this error message but at first I couldn't find out what caused it. After doing some tests I actually found out that removing all margins on the View (in your example the fragment) seems to remove the problem.

So in your case it would be:

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_list"
    android:name="com.navdrawertest.ItemListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ItemListActivity"
    tools:layout="@android:layout/list_content" />

and you can set margins on all the views inside this fragment instead (but I haven't tested it). Hope it helps someone. It seems that this problem is not so common.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...