当前位置: 首页 > 知识库问答 >
问题:

Android资源$NotFoundException崩溃报告

耿炎彬
2023-03-14

我一直收到同样的撞车报告,扔了一个Android。所容纳之物res.Resources$NotFoundException错误,抱怨缺少资源ID。

谁能解释一下错误是什么吗?我看到一些帖子谈到导航视图(NavigationView)是个问题。其他人提到了v21可绘制资源,但我的应用程序中没有任何v21可绘制资源。

如果你看到过回答这个问题的帖子,请告诉我。否则,我们将不胜感激!

下面是其中一个崩溃报告的堆栈跟踪。

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raimikarim.arabicconjugator/com.raimikarim.arabicconjugatorpro.Conjugation.SmartConjugateActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2065)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2090)
at android.app.ActivityThread.access$600(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4802)
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:813)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.raimikarim.arabicconjugatorpro.Conjugation.SmartConjugateActivity.onCreate(SmartConjugateActivity.java:64)
at android.app.Activity.performCreate(Activity.java:5013)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029)
... 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:587)
... 22 more
    Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02006c
at android.content.res.Resources.getValue(Resources.java:1017)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:321)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:495)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:245)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)

这是我的styles.xml

    <resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary_color</item>
    <item name="colorPrimaryDark">@color/primary_dark_color</item>
    <item name="actionBarStyle">@style/ConjogetAppBarStyle</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
</style>

<!-- Spinner design -->
<style name="SpinnerStyle" parent="Widget.AppCompat.ListView.DropDown">
    <item name="android:divider">#d1d1d1</item>
    <item name="android:dividerHeight">0.5dp</item>
</style>

<!-- App bar style -->
<style name="ConjogetAppBarStyle" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <!-- Remove the shadow below the app bar -->
    <item name="elevation">0dp</item>
</style>

<!-- Style for a tab that displays a category name -->
<style name="category_tab" parent="Widget.Design.TabLayout">
    <item name="tabIndicatorColor">@color/primary_color</item>
    <item name="tabSelectedTextColor">@color/primary_dark_color</item>
    <item name="tabTextAppearance">@style/CategoryTabTextAppearance</item>
</style>

<!-- Text appearance style for a category tab -->
<style name="CategoryTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textColor">#A8A19E</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

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

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowDisablePreview">true</item>
</style>

<style name="edittext">
    <item name="android:layout_width">140dp</item>
    <item name="android:layout_height">60dp</item>
    <item name="android:gravity">center</item>
    <item name="android:textSize">32sp</item>
    <item name="android:background">@drawable/edit_text_style</item>
    <item name="android:singleLine">true</item> // so that user goes to next edittext after input
</style>
<style name="Theme.Transparent2" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

还有我的风格。xml(v21)

<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>

共有2个答案

仲孙鸿飞
2023-03-14

解决了的!我刚刚将XML drawable移到drawable/文件夹。就像魔术一样。感谢@ligi。

KitKat及以下版本上的VectorDrawableCompat资源$NotFoundException

雍嘉勋
2023-03-14

更改样式。xml主题。。。

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">#673AB7</item>
    <item name="colorPrimaryDark">#512DA8</item>
    <item name="colorAccent">#00BCD4</item>
    <item name="android:textColorPrimary">#212121</item>
    <item name="android:textColorSecondary">#727272</item>

</style>

适用于我,当我删除android: text ColorFirst和android: text Color二级主题项目。

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">#673AB7</item>
    <item name="colorPrimaryDark">#512DA8</item>
    <item name="colorAccent">#00BCD4</item>

</style>
 类似资料: