gpt4 book ai didi

android.graphics.drawable.AdaptiveIconDrawable 无法转换为 android.graphics.drawable.BitmapDrawable 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:39:05 37 4
gpt4 key购买 nike

当我的应用程序在启动时崩溃时尝试实现自适应图标时出现此错误。

我无法想象为什么会收到此错误,因为在下面错误日志中提到的文件(MainActivityBaseActivity)中,我没有使用AdaptiveIconDrawableBitmapDrawable

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”文件夹时,我的应用程序不再崩溃,但自适应图标也无法正常工作...

抛出错误的行在这两种情况下都是:

super.onCreate(savedInstanceState);

最佳答案

在 ATE.java 文件中,实现这个

@NonNull
static private Bitmap getBitmapFromDrawable(@NonNull Drawable drawable) {
final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bmp);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bmp;
}

并改变

if (icon == null)
icon = ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap();

if (icon == null)
icon = getBitmapFromDrawable(activity.getApplicationInfo().loadIcon(activity.getPackageManager()));

关于android.graphics.drawable.AdaptiveIconDrawable 无法转换为 android.graphics.drawable.BitmapDrawable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50077917/

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