问题描述
当我的应用在启动时崩溃时,尝试实现自适应图标时出现此错误.
I'm getting this error when trying to implement Adaptive Icons while my app crashes on startup.
我无法想象为什么会出现此错误,因为在下面的错误日志中提到的文件(MainActivity
和BaseActivity
)中,我没有同时使用AdaptiveIconDrawable
和BitmapDrawable
./p>
I can't imagine why I'm getting this error because in the files mentioned in the error log below (MainActivity
and BaseActivity
), I don't use both AdaptiveIconDrawable
and BitmapDrawable
.
2018-04-28 16:50:17.014 31282-31282/de.markustippner.wondermusic2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.markustippner.wondermusic2, PID: 31282
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.markustippner.wondermusic2/de.markustippner.wondermusic2.activities.MainActivity}: java.lang.ClassCastException: android.graphics.drawable.AdaptiveIconDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3027)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:101)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:73)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ClassCastException: android.graphics.drawable.AdaptiveIconDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
at com.afollestad.appthemeengine.ATE.applyTaskDescription(ATE.java:259)
at com.afollestad.appthemeengine.ATE.preApply(ATE.java:128)
at com.afollestad.appthemeengine.ATEActivity.onCreate(ATEActivity.java:22)
at de.markustippner.wondermusic2.activities.BaseActivity.onCreate(BaseActivity.java:44)
at de.markustippner.wondermusic2.activities.MainActivity.onCreate(MainActivity.java:137)
at android.app.Activity.performCreate(Activity.java:7117)
at android.app.Activity.performCreate(Activity.java:7108)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2867)
出现此错误消息的有趣"部分是,当我删除"mipmap-anydpi-v26"文件夹时,我的应用程序不再崩溃,但自适应图标也无法正常工作...
The "funny" part with this error message is that when I remove "mipmap-anydpi-v26" folder, my app doesn't crash anymore but then Adaptive Icons are not working too...
在两种情况下抛出错误的行:
The lines where the error is thrown are in both cases:
super.onCreate(savedInstanceState);
推荐答案
似乎您正在使用 App Theme Engine ,它会尝试将您的应用程序图标用作位图.但是从Android 8.0开始,您可以设置自适应图标(不是位图),因此App Theme Engine崩溃.
It appears you're using App Theme Engine, which tries to use you app icon as a bitmap. But since Android 8.0 you can set an adaptive icon, which is not a bitmap, thus the App Theme Engine crashes on it.
此问题已在此处报告,但尚未得到已修复(可能不会,因为两年未见任何更新).
This issue has been reported here, but it's not been fixed yet (and probably won't, since it hasn't seen any updates for two years).
通过分叉项目并更改问题部分,不需要位图图标.或者,使用其他主题引擎.
You might be able so fix this yourself by forking the project and changing the problematic part to not require a bitmap icon. Or alternatively, use another theme engine.
这篇关于android.graphics.drawable.AdaptiveIconDrawable无法转换为android.graphics.drawable.BitmapDrawable错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!