导航抽屉例外

时间:2018-07-31 16:29:02

标签: android android-layout

当我启动一个具有导航抽屉的活动时,我的应用程序出现问题,我在日志文件中收到该错误,应用程序崩溃。

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.nasrmohamed.winners_ten_aux, PID: 3268
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nasrmohamed.winners_ten_aux/com.example.nasrmohamed.winners_ten_aux.ui.home.HomeActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2193)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243)
                  at android.app.ActivityThread.access$800(ActivityThread.java:135)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5019)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView
                  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                  at com.example.nasrmohamed.winners_ten_aux.ui.home.HomeActivity.onCreate(HomeActivity.java:51)
                  at android.app.Activity.performCreate(Activity.java:5231)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) 
                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:136) 
                  at android.app.ActivityThread.main(ActivityThread.java:5019) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:515) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.constructNative(Native Method)
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                  at com.example.nasrmohamed.winners_ten_aux.ui.home.HomeActivity.onCreate(HomeActivity.java:51) 
                  at android.app.Activity.performCreate(Activity.java:5231) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) 
                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:136) 
                  at android.app.ActivityThread.main(ActivityThread.java:5019) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:515) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f080084
                  at android.content.res.Resources.getValue(Resources.java:1123)
                  at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:328)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
                  at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                  at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:491)
                  at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:519)
                  at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:460)
                  at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:117)
                  at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:250)
                  at android.support.design.widget.NavigationView.<init>(NavigationView.java:172)
                  at android.support.design.widget.NavigationView.<init>(NavigationView.java:98)
                  at java.lang.reflect.Constructor.constructNative(Native Method) 
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                  at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                  at com.example.nasrmohamed.winners_ten_aux.ui.home.HomeActivity.onCreate(HomeActivity.java:51) 
                  at android.app.Activity.performCreate(Activity.java:5231) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) 
                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:136) 
                  at android.app.ActivityThread.main(ActivityThread.java:5019) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:515) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                  at dalvik.system.NativeStart.main(Native Method) 

她是我的style.xml文件:

    <resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="EditText_style">
        <item name="android:background">@drawable/edittext_background</item>
        <item name="android:gravity">center</item>
        <item name="android:textSize">12sp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:ems">10</item>
        <item name="android:layout_margin">5dp</item>
    </style>

    <style name="Button_style">
        <item name="android:background">@drawable/button_background</item>
        <item name="android:layout_margin">5dp</item>
        <item name="android:textColor">#FDFDFE</item>
    </style>

    <style name="TextView_style">
        <item name="android:layout_margin">5dp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">@color/white</item>
    </style>


    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>


</resources>

这是我的activity_home.xml文件

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_home_drawer" />

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

我的nav_header_layout:

<?xml version="1.0" encoding="utf-8"?>
<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="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/image_user_nav_drawer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nav_header_desc"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@drawable/user" />

    <TextView
        android:id="@+id/txt_user_name_nav_drawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

</LinearLayout>

我的菜单布局:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_profile"
            android:icon="@drawable/ic_account"
            android:title="@string/profile" />
        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_settings"
            android:title="@string/settings" />
        <item
            android:id="@+id/nav_help"
            android:icon="@drawable/ic_help"
            android:title="@string/help" />
        <item
            android:id="@+id/nav_condition"
            android:icon="@drawable/ic_information"
            android:title="@string/conditions" />
        <item
            android:id="@+id/nav_logout"
            android:icon="@drawable/ic_logout"
            android:title="@string/logout" />
    </group>

</menu>

知道,当我在具有更高api(例如sone xperia z2)的设备上对其进行测试时,它可以完美运行。 任何帮助将不胜感激, 预先感谢。

0 个答案:

没有答案