毕加索不能容忍空的字符串URL吗? [英] Picasso doesn't tolerate empty String URL?

查看:113
本文介绍了毕加索不能容忍空的字符串URL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个viewHolder可以使用毕加索加载图像. DB将返回URL的路径作为String.所以我的代码如下(使用Kotlin)

I have a viewHolder that loads up an image using Picasso. The DB will return a path of URL as String. So I have my code as below (Using Kotlin)

  Picasso.with(context).load(url).error(placeholder).transform(transformation)
            .placeholder(placeholder).into(this)

加载正常.但是,有时URL为空.我期望它代替加载占位符.但它崩溃如下所示

It loads fine. However, sometimes the URL is empty. I'm expecting it to load the placeholder instead. But it crash out as below

java.lang.IllegalArgumentException: Path must not be empty.
    at com.squareup.picasso.Picasso.load(Picasso.java:297)

这将迫使我明确进行检查,这不理想

This would force me to explicitly do a check, which is not ideal

if (url == null || url.isEmpty()) {
    Picasso.with(context).load(placeholder).transform(transformation).into(this)
} else {
    Picasso.with(context).load(url).error(placeholder).transform(transformation)
            .placeholder(placeholder).into(this)
}

是否期望URL字符串为空而不是加载占位符时毕加索会崩溃?

Is this expected that Picasso will crash when a URL String is empty instead of loading the placeholder?

推荐答案

javadoc for Picasso.load()明确指出,如果URL为null或为空,它将抛出IllegalArgumentException.这就是您所期望的.

The javadoc for Picasso.load() explicitly states that it will throw an IllegalArgumentException when the URL is null or empty. So that's what you can expect.

这篇关于毕加索不能容忍空的字符串URL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆