Android 4.2上的“错误输出类android.support.design.widget.NavigationView”

时间:2016-04-23 18:53:17

标签: android android-support-library android-navigation-drawer android-navigationview

我有多个崩溃报告,其中包含以下堆栈跟踪。所有这些都来自Android 4.2上的各种三星设备。我无法使用模拟器重现。有没有人对可能导致这种情况的原因有任何想法?

我的下一个版本将从支持库版本23.1.1升级到23.2.1,但我不知道这是否有帮助,因为我无法重现。

堆栈追踪:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsouth.myapp/com.nsouth.myapp.Activity_Main}: android.view.InflateException: Binary XML file line #35: Error inflating class android.support.design.widget.NavigationView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2301)
    at android.app.ActivityThread.access$700(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5285)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class android.support.design.widget.NavigationView
    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:256)
    at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:109)
    at com.nsouth.myapp.Activity_Main.onCreate(SourceFile:331)
    at android.app.Activity.performCreate(Activity.java:5284)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    ... 11 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    at android.view.LayoutInflater.createView(LayoutInflater.java:593)
    ... 23 more
Caused by: java.lang.NoClassDefFoundError: android.support.design.internal.a
    at android.support.design.widget.NavigationView.<init>(SourceFile:103)
    at android.support.design.widget.NavigationView.<init>(SourceFile:94)
    ... 26 more

主要布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- To show drawer over toolbar, move this down to right above frameLayout -->

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />

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

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/content_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/bg_offwhite">

            <FrameLayout
                android:id="@+id/main_frag_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.NsouthProductions.gradetrackerpro.Activity_Main"
                tools:ignore="MergeRootFrame" />

        </RelativeLayout>

        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_view"
            android:layout_width="290dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:theme="@style/MyNavViewTheme"
            app:headerLayout="@layout/nav_drawer_header"
            app:menu="@menu/nav_drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="-80dp"
        android:id="@+id/snackbarPosition">
    </android.support.design.widget.CoordinatorLayout>

</LinearLayout>

样式

<style name="MyNavViewTheme" parent="AppTheme.Base">
        <item name="colorControlHighlight">#eeeeee</item>
    </style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/primary_text</item>
        <item name="android:textColorSecondary">@color/secondary_text</item> <!-- these 2 might need android prefix? -->
        <item name="android:divider">@color/divider</item>
        <item name="android:windowBackground">@android:color/white</item>
    </style>

Gradle依赖

compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

1 个答案:

答案 0 :(得分:0)

尽量不要在android:中使用styles.xml前缀。 Material主题中不需要AppCompat主题中的内容。由于您使用的是AppCompat主题,请按照以下方式使用:

 <item name="textColorPrimary">@color/primary_text</item>
 <item name="textColorSecondary">@color/secondary_text</item>

更多reference