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

LittleFunny picture LittleFunny · Sep 9, 2014 · Viewed 47.9k times · Source

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?

Answer

Kevin van Mierlo picture Kevin van Mierlo · Jun 3, 2015

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) {
                }
            })