简体   繁体   English

毕加索图库加载错误

[英]Picasso Library Load Error

I'm using the Picasso library to dynamically load images from an API call. 我正在使用Picasso库从API调用动态加载图像。

Certain urls seem to return a malformed URL, for example: "http://imagesite.com/image.1241123.gif which crashes the app. 某些网址似乎返回格式错误的网址,例如: "http://imagesite.com/image.1241123.gif ,这会使应用程序崩溃。

  Picasso.with(activity).load(image)
.centerCrop()
    .error(R.drawable.icon01)
    .resize(50, 50)
    .into(icon);

Looking at the documentation, I assumed the .error() parameter would handle this, but Picasso seems to see it as a valid URL, even though it won't return an image. 查看文档,我假设.error()参数可以处理此问题,但是Picasso似乎将其视为有效的URL,即使它不会返回图像也是如此。 I've also tried using the Picasso.Builder but I continue to get the same errors. 我也尝试过使用Picasso.Builder但仍然出现相同的错误。 Any suggestions? 有什么建议么?

picasso don't load gif image for that you have to use Glide library. 由于必须使用Glide库,因此Picasso不会加载gif图像。 Check this link it might help you : http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en 检查此链接可能会对您有所帮助: http : //inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

and you get library from : https://github.com/bumptech/glide 并且您从以下网址获取库: https : //github.com/bumptech/glide

error() will handle issues where the URL is well formed but for some reasons it cannot display the image. error()将处理URL格式正确的问题,但由于某些原因,它将无法显示图像。

If you have malformed url it means the problem is your data. 如果网址格式错误,则意味着问题出在您的数据上。 Remember garbage in , garbage out. 记住垃圾进,垃圾出。

Use Uri.parse() before loading it to picasso, then handle the thrown exception: better fix your data. 在将其加载到毕加索之前使用Uri.parse() ,然后处理引发的异常:更好地修复数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM