gpt4 book ai didi

android - 启动画面错误 : android. content.res.Resources$NotFoundException: Drawable

转载 作者:IT老高 更新时间:2023-10-28 13:47:06 28 4
gpt4 key购买 nike

我正在尝试通过以下操作在我的 android 应用程序中实现启动画面 this article .我一步一步地遵循它,但是每当我尝试运行该应用程序时,它会立即崩溃,并且我的 logcat 中出现以下错误:

2019-01-05 10:46:33.682 2265-2265/com.example.khoi.parkingapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.khoi.parkingapp, PID: 2265
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.khoi.parkingapp/com.example.khoi.parkingapp.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.example.khoi.parkingapp:drawable/splash_background with resource ID #0x7f07008d
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.khoi.parkingapp:drawable/splash_background with resource ID #0x7f07008d
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background.xml from drawable resource ID #0x7f07008d
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:837)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659)
at android.content.res.Resources.getDrawableForDensity(Resources.java:891)
at android.content.res.Resources.getDrawable(Resources.java:833)
at android.content.Context.getDrawable(Context.java:605)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at android.support.v7.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at com.example.khoi.parkingapp.SplashActivity.onCreate(SplashActivity.kt:10)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <bitmap> requires a valid 'src' attribute
at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:823)
at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:754)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:146)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1322)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1311)
at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:284)
at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:146)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1322)
2019-01-05 10:46:33.682 2265-2265/com.example.khoi.parkingapp E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1281)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:824)
... 24 more

这是我的 splash_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@color/colorPrimary"/>

<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>

</layer-list>

任何帮助将不胜感激

最佳答案

感谢 Alexander 缩小错误范围,我找到了 post这完全解决了我的问题:

我将我的 splash_background.xml 修复为:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorPrimary"/>

<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_launcher"/>
</item>

</layer-list>

显然,您需要的 src 需要位于 drawable 文件夹中,并且它是 .png 而不是 .xml

关于android - 启动画面错误 : android. content.res.Resources$NotFoundException: Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54053614/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com