gpt4 book ai didi

java - 处理 Picasso(重新)抛出的异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:32 29 4
gpt4 key购买 nike

是否可以捕获这样的异常?我可以使用 Thread.UncaughtExceptionHandler 吗?

java.lang.IllegalArgumentException: RemoteViews for widget update exceeds maximum bitmap memory usage (used: 1000000, max: 921600) The total memory cannot exceed that required to fill the device's screen once.
at android.os.Parcel.readException(Parcel.java:1429)
at android.os.Parcel.readException(Parcel.java:1379)
at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:523)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:333)
at com.squareup.picasso.RemoteViewsAction$AppWidgetAction.update(RemoteViewsAction.java:99)
at com.squareup.picasso.RemoteViewsAction.complete(RemoteViewsAction.java:43)
at com.squareup.picasso.Picasso.deliverAction(Picasso.java:511)
at com.squareup.picasso.Picasso.complete(Picasso.java:470)
at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:115)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4963)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)

我看到 Picasso 使用 Handler 抛出异常:

Picasso.HANDLER.post(new Runnable() { ...

是否可以从我的代码中捕获此异常?

最佳答案

开发者网站中:

The total Bitmap memory used by the RemoteViews object cannot exceed that required to fill the screen 1.5 times, ie. (screen width x screen height x 4 x 1.5) bytes.

在您的特定情况下,当从流加载的位图大于可能的大小时,就会发生错误。

您需要在比较后解码图像以获得适合您的布局的尺寸!

或通过 picasso 库上的.resize(imageWidth, imageHight)!

希望这有帮助:) ..

关于java - 处理 Picasso(重新)抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28380014/

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