大约一周前,我最近开始在一个新项目中使用 DrawerLayout,一切正常。除了用我的手指刷入和刷出的奇怪时间之外,它会崩溃。
如果我使用 ActionBar Up/Home MenuItem,它每次都能正常工作。
在 LogCat 中,我得到两个似乎都指向内部 android 位置的堆栈跟踪,所以我不太清楚如何解决这个问题。
我只是尝试创建一个新应用程序,看看是否是我之前正在做的事情导致了这种情况,但它也发生在新应用程序中。
我在“新 Android 应用程序”窗口中使用 Master/Detail Flow 模板创建了新应用程序,将所有内容保留为默认值,并更改了 activity_item_list.xml 以在其中包含以下内容:
<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>
DrawerLayout 显示,我仍然可以从屏幕边缘拖动它,但它仍然在这个测试应用程序中崩溃。
这是我用手指拖动它后看到的堆栈跟踪:
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 android.os.Looper.loop(Looper.java:124)
07-26 09:29:45.594: E/AndroidRuntime(19085): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-26 09:29:45.594: E/AndroidRuntime(19085): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 09:29:45.594: E/AndroidRuntime(19085): at java.lang.reflect.Method.invoke(Method.java:525)
07-26 09:29:45.594: E/AndroidRuntime(19085): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-26 09:29:45.594: E/AndroidRuntime(19085): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-26 09:29:45.594: E/AndroidRuntime(19085): at dalvik.system.NativeStart.main(Native Method)
我在这里缺少什么吗?
编辑:10天后仍然无法弄清楚,我至少可以确认这不仅仅是我得到这个吗?