如何修复FATAL EXCEPTION:主要android.content.res.Resources $ NotFoundException

时间:2016-12-16 20:33:48

标签: android android-appcompat android-resources

当我尝试在Android 4.1上运行我的应用时会出现错误,但它适用于API级别21以上的任何内容。

^/book/.*\b[tT][Ee][Ss][Tt][sS]?\b
                           ^^^^^^^

我已经按照教程更改了工具栏,以便我可以更改文本的背景颜色,但它不仅仅适用于API 21以下的任何内容。有关如何修复它的任何想法?它让我发疯了。

这些是我在更改颜色时主要更改的文件,因此我认为问题出在这些文件中。

styles.xml

FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x7f020059
at android.content.res.Resources.getValue(Resources.java:1013)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:327)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:185)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.design.internal.NavigationMenuItemView.initialize(NavigationMenuItemView.java:113)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder(NavigationMenuPresenter.java:415)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder(NavigationMenuPresenter.java:338)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5825)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5094)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1868)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1689)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.C

app_bar_main.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppTheme.Base" >
    <!-- Base application theme.
         Defining this lets values-v21/styles.xml reuse it with changes. -->
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
        <!-- colorPrimary is used, for instance, for the default ActionBar
             (but not Toolbar) background.
              We specify the same color for the toolbar background in
              toolbar.xml.. -->
        <item name="colorPrimary">@color/colorPrimary</item>

        <!-- colorPrimaryDark is used for the status bar (with the
             battery, clock, etc). -->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <!-- colorAccent is used as the default value for
             colorControlActivated which is used to tint widgets. -->
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    <style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
        <!-- android:textColorPrimary is the  color of the title text
             in the Toolbar, in the Theme.AppCompat theme:  -->
        <item name="android:textColorPrimary">#4e4e4e</item>

        <!-- android:textColorPrimaryInverse is the  color of the title
             text in the Toolbar, in the Theme.AppCompat.Light theme:  -->
        <!-- <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item> -->

        <!-- android:actionMenuTextColor is the color of the text of
              action (menu) items in the Toolbar, at least in the
              Theme.AppCompat theme.
              For some reason, they already get the textColorPrimary
              when running on API 21, but not on older versions of
              Android, so this is only necessary to support older
              Android versions.-->
        <item name="actionMenuTextColor">@color/abc_primary_text_material_light</item>
        <!-- android:textColorSecondary is the color of the menu
             overflow icon (three vertical dots) -->
        <item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>

        <!-- This would set the toolbar's background color,
              but setting this also changes the popup menu's background,
              even if we define popupTheme for our <Toolbar> -->
        <!-- <item name="android:background">@color/color_primary</item> -->
    </style>

</resources>

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.dawsn.fitigniterapp.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:theme="@style/GalaxyZooThemeToolbarDarkOverflow"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main"/>

</android.support.design.widget.CoordinatorLayout>

styles.xml(v21)

<?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: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"
    android:orientation="vertical"
    android:gravity="bottom">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="You are not logged in"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:id="@+id/txtUserName"
        android:textColor="@color/navheadertext" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Please log into see your details"
        android:id="@+id/txtNotLogged"
        android:textColor="@android:color/black" />

</LinearLayout>

的AndroidManifest.xml

<resources>
    <style name="AppTheme.NoActionBar" >
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

0 个答案:

没有答案