处理毕加索(重新)抛出的异常

时间:2015-02-07 08:15:36

标签: java android picasso

是否有可能捕获这些异常?我可以使用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() { ...

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

1 个答案:

答案 0 :(得分:0)

开发者网站:

  

RemoteViews对象使用的总位图内存不能超过   需要填充屏幕1.5次,即。 (屏幕宽度x屏幕   身高x 4 x 1.5)字节。

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

您需要在比较后解码图像,以确定布局的正确尺寸!

或通过Picasso图书馆的.resize(imageWidth, imageHight)

希望这有帮助:) ..