java.lang.IllegalArgumentException:毕加索中的路径不能为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35721692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalArgumentException: Path must not be empty in Picasso
提问by user2269164
I am loading image from mysql DB using Picasso into custom listview. The image is loading when the URL is passed directly but when i assign the URL to string and pass it then it throws exception saying Path must not be empty.
我正在使用 Picasso 将 mysql DB 中的图像加载到自定义列表视图中。当直接传递 URL 时图像正在加载,但是当我将 URL 分配给字符串并传递它时,它会抛出异常,说 Path 不能为空。
String imageStringUrl = md.Image;
Image string contains http://example.com/image.jpg
图像字符串包含http://example.com/image.jpg
I am passing in Picasso like below.
我正在像下面这样经过毕加索。
Picasso.get()
.load(imageStringUrl)
.into(iview);
When I pass like this I am getting java.lang.IllegalArgumentException: Path must not be empty. I have tried the above step like below but the image is not loading.
当我这样通过时,我得到 java.lang.IllegalArgumentException: Path must not be empty。我已经尝试过如下所示的上述步骤,但图像未加载。
Picasso.get()
.load(new File(imageStringUrl))
.into(iview);
What is wrong with the above declaration?
上面的声明有什么问题?
回答by HassanUsman
I think your md.Image
is returning an empty string. So try directly put your image url
in picasso
like this:
我认为您md.Image
正在返回一个空字符串。所以尝试直接把你image url
的picasso
像这样:
Picasso.get()
.load(" http://xxx.xxx.com/images/New%20folder/Desert.jpg.")
.into(imageView);
Hope it works.
希望它有效。
回答by veena
I had a similar problem. Just check if your URL string is empty or not. if it is empty give the default image or load from URL. Hope this helps.
我有一个类似的问题。只需检查您的 URL 字符串是否为空。如果为空,则提供默认图像或从 URL 加载。希望这可以帮助。
if (image.isEmpty()) {
iview.setImageResource(R.drawable.placeholder);
} else{
Picasso.get().load(image).into(iview);
}
回答by ozmank
Just check if your url string is empty or not by first trimming the string path, but do not check like image.isEmpty()
but with this check:
只需通过首先修剪字符串路径来检查您的 url 字符串是否为空,但不要image.isEmpty()
使用此检查进行检查:
if (path.trim().length() == 0)
I checked the code from Picasso and that is how they are checking like this. For reference here is code from their code base:
我检查了毕加索的代码,他们就是这样检查的。作为参考,这里是他们代码库中的代码:
public RequestCreator load(String path) {
if (path == null) {
return new RequestCreator(this, null, 0);
}
if (path.trim().length() == 0) {
throw new IllegalArgumentException("Path must not be empty.");
}
return load(Uri.parse(path));
}