启动画面仅在Android 8.1上触发Resources $ NotFoundException [英] Splash Screen triggers Resources$NotFoundException only on Android 8.1

查看:182
本文介绍了启动画面仅在Android 8.1上触发Resources $ NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里逐步地本教程 ,它可以在我的API 21仿真器上正常工作,但在我的27仿真器上,应用程序加载后立即崩溃:

I followed this tutorial here step by step, it works fine on my API 21 emulator, but on my 27 it crashes as soon as the app loads with:

java.lang.RuntimeException:无法启动活动ComponentInfo {com.myapp.myapp/com.myapp.myapp.ui.SplashScreenActivity}:android.content.res.Resources $ NotFoundException:Drawable com.myapp.myapp:drawable/splash_screen_background,资源ID为#0x7f0700a9

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.myapp/com.myapp.myapp.ui.SplashScreenActivity}: android.content.res.Resources$NotFoundException: Drawable com.myapp.myapp:drawable/splash_screen_background with resource ID #0x7f0700a9

我的文件drawable/splash_screen_background是这个文件:

My file drawable/splash_screen_background is this one:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:type="radial"
                android:gradientRadius="100%p"
                android:startColor="@color/primaryColor"
                android:endColor="@color/primaryDarkColor"/>
        </shape>
    </item>

    <item>
        <bitmap
        android:gravity="center"
            android:src="@drawable/ic_home_white_24dp"/>
    </item>
</layer-list>

我尝试使用app:srcCompat,将drawable直接传递给item,从而消除了bitmap,但问题仍然存在.我见过有人说使用android:drawable=代替,但是他们说这在<上崩溃了. API 21.

I tried to use app:srcCompat, pass the drawable directly to the item eliminating the bitmap, but the problem persists. I have seen some people saying to use android:drawable= instead, but they say this crashes on < API 21.

此答案显示了一些非常复杂的额外配置,包括gradle选项,我不确定这将如何影响我的应用程序,它会改变矢量图形的性能吗?

This answer shows some pretty complicated extra configurations, including gradle options, I am not sure how this will impact my app, does it change the performance of vector graphics?

在Android上处理可在多个API上使用的layer-list的正确方法是什么?

What's the right way to handle a layer-list on Android that will work on several APIs?

推荐答案

就像您在注释中建议的那样,该问题的解决方案是,您的资源不在可绘制的文件夹中.

Like you have suggested in your comment, the solution to the problem is, that your resources are not in the drawable folder.

所有可绘制资源文件也应位于可绘制"中.如果您具有较高Android版本的特殊功能,则可以将文件上传到"drawable-v21","drawable-v24",...

All your drawable resource files should be in "drawable" too. If you have special features for higher android versions, you can uploaded files in "drawable-v21", "drawable-v24", ...

我希望这会有所帮助,我遇到了同样的问题,将来自不同drawable文件夹的所有资源放入全局drawable文件夹后,我的问题得到了解决.

I hope that will help, i had the same problem and after putting every resource from different drawable folder in the global drawable folder, my problem was solved.

这篇关于启动画面仅在Android 8.1上触发Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆