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)
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)
}
Is this expected that Picasso will crash when a URL String is empty instead of loading the placeholder?
This might be too late but i encountered this error today and after read the documentation of Picasso#load method it states that passing empty or blank string will cause the method to throw IllegalArgumentException
and passing a null will not throw an exception but trigger RequestCreator#error which will load error image if one is provided otherwise the target will display nothing.
if you have no control over the image url (say its coming from server) you can try the following:
mPicasso.load(photo.isEmpty() ? null : photo)
.placeholder(placeholder)
.error(error_placeholder)
.into(target);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With