我正在尝试使用官方教程从支持库中使用 DrawerLayout,但是每当我尝试运行我的应用程序时,我都会崩溃。阅读以下日志后,我无法确定我的代码中导致此崩溃的位置。
06-16 21:14:55.272: E/AndroidRuntime(20104): FATAL EXCEPTION: main
06-16 21:14:55.272: E/AndroidRuntime(20104): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
06-16 21:14:55.272: E/AndroidRuntime(20104): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.AbsListView.obtainView(AbsListView.java:1340)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ListView.makeAndAddView(ListView.java:1789)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ListView.fillDown(ListView.java:656)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ListView.fillFromTop(ListView.java:722)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.ListView.layoutChildren(ListView.java:1624)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.AbsListView.onLayout(AbsListView.java:1172)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.View.layout(View.java:7080)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:672)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.View.layout(View.java:7080)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.View.layout(View.java:7080)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.View.layout(View.java:7080)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.ViewRoot.performTraversals(ViewRoot.java:1056)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.ViewRoot.handleMessage(ViewRoot.java:1738)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.os.Looper.loop(Looper.java:143)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.app.ActivityThread.main(ActivityThread.java:4717)
06-16 21:14:55.272: E/AndroidRuntime(20104): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 21:14:55.272: E/AndroidRuntime(20104): at java.lang.reflect.Method.invoke(Method.java:521)
06-16 21:14:55.272: E/AndroidRuntime(20104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-16 21:14:55.272: E/AndroidRuntime(20104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-16 21:14:55.272: E/AndroidRuntime(20104): at dalvik.system.NativeStart.main(Native Method)
06-16 21:14:55.272: E/AndroidRuntime(20104): Caused by: java.lang.reflect.InvocationTargetException
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.TextView.<init>(TextView.java:426)
06-16 21:14:55.272: E/AndroidRuntime(20104): at java.lang.reflect.Constructor.constructNative(Native Method)
06-16 21:14:55.272: E/AndroidRuntime(20104): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
06-16 21:14:55.272: E/AndroidRuntime(20104): ... 29 more
06-16 21:14:55.272: E/AndroidRuntime(20104): Caused by: android.content.res.Resources$NotFoundException: File res/color/primary_text_dark.xml from drawable resource ID #0x0
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.content.res.Resources.loadDrawable(Resources.java:1725)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.view.View.<init>(View.java:1902)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.widget.TextView.<init>(TextView.java:432)
06-16 21:14:55.272: E/AndroidRuntime(20104): ... 33 more
06-16 21:14:55.272: E/AndroidRuntime(20104): Caused by: android.content.res.Resources$NotFoundException: File res/color/primary_text_dark.xml from xml type drawable resource ID #0x0
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1952)
06-16 21:14:55.272: E/AndroidRuntime(20104): at android.content.res.Resources.loadDrawable(Resources.java:1720)
06-16 21:14:55.272: E/AndroidRuntime(20104): ... 36 more
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The 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:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
我的drawer_list_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
如果需要更多信息,请发表评论,我会更新问题。