Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Picasso load image failed . how to show error message

I am trying to use the picasso library to loading the image store in the mediastore. When I called load(imageview, callback), the picasso call onFail instead of onSuccess. How do I know why the image was not loaded successfully?

like image 507
LittleFunny Avatar asked Sep 09 '14 12:09

LittleFunny


People also ask

How will you load an image into an imageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.


2 Answers

Use builder:

    Picasso.Builder builder = new Picasso.Builder(this);     builder.listener(new Picasso.Listener()     {         @Override         public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)         {             exception.printStackTrace();         }     });     builder.build().load(URL).into(imageView); 

Edit

For version 2.71828 they have added the exception to the onError callback:

        Picasso.get()             .load("yoururlhere")             .into(imageView, new Callback() {                 @Override                 public void onSuccess() {                 }                  @Override                 public void onError(Exception e) {                 }             }) 
like image 184
Kevin van Mierlo Avatar answered Sep 17 '22 10:09

Kevin van Mierlo


When you use callback, the picaso will call method onSuccess and onError!

File fileImage = new File(mPathImage);         Picasso.with(mContext).load(fileImage)                 .placeholder(R.drawable.draw_detailed_view_display)                 .error(R.drawable.draw_detailed_view_display)                 .resize(200, 200)                 .into(holder.mImageEvidence, new Callback() {                     @Override                     public void onSuccess() {                         holder.mMediaEvidencePb.setVisibility(View.GONE);                     }                      @Override                     public void onError() {                         holder.mErrorImage.setVisibility(View.VISIBLE);                     }                 }); 
like image 21
TVT. Jake Avatar answered Sep 20 '22 10:09

TVT. Jake