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

后端 未结 6 546
后悔当初
后悔当初 2020-11-29 02:37

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. H

相关标签:
6条回答
  • 2020-11-29 03:10

    Have you added internet permission in Manifest? With Kevin's answer here, Please see the exception log and post the exception here.

    0 讨论(0)
  • 2020-11-29 03:14

    In case you want to use Picasso with Kotlin and lambda expression it could be as short as this:

    val picasso = Picasso.Builder(context)
                .listener { _, _, e -> e.printStackTrace() }
                .build()
    

    ...and then you can load image as usual:

    picasso.load(url).into(imageView)
    
    0 讨论(0)
  • 2020-11-29 03:20
    val picasso = Picasso.Builder(context).listener(
                        object : Picasso.Listener{
                            override fun onImageLoadFailed(picasso: Picasso?, uri: Uri?, exception: Exception?) {
                                exception?.printStackTrace()
                                println("Picasso loading failed : ${exception?.message}")
                            }
    
                        }
                ).build()
    picasso.load(imageUrl).into(imageView)
    
    0 讨论(0)
  • 2020-11-29 03:23

    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) {
                    }
                })
    
    0 讨论(0)
  • 2020-11-29 03:29

    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);
                        }
                    });
    
    0 讨论(0)
  • 2020-11-29 03:33

    Please try this to check logs of the Picasso

    Picasso.with(getContext()).setLoggingEnabled(true);
    
    0 讨论(0)
提交回复
热议问题