Picasso Load Image Failed and App Crashing

后端 未结 2 1129
情深已故
情深已故 2021-01-16 16:02

I\'m new to Android development, I\'m trying to load image from url using Picasso, but it failed when I navigate to the Picasso loading activity.

Below is the code t

相关标签:
2条回答
  • 2021-01-16 16:35

    From what I see, you spent a reference to the instance of the activity Context context = this; outside Oncreat method (), so be getting NullPointerException

    Here

    Picasso.with(context).load("http://postimg.org/image/wjidfl5pd/").into(ImageView1);
    

    the context variable is null

    Change this:

    //Declaring Variable
    ImageView ImageView1 = (ImageView)findViewById(R.id.forthImage);
    Context context = this;
    

    By:

    //In onCreate()  
    
    ImageView ImageView1 = (ImageView)findViewById(R.id.forthImage);  
    Picasso.with(this).load("http://postimg.org/image/wjidfl5pd/").into(ImageView1);
    
    0 讨论(0)
  • 2021-01-16 16:50
    final Target mTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
                Log.d("DEBUG", "onBitmapLoaded");
                progress_bar.setVisibility(View.GONE);
                cropImageView.setImageBitmap(bitmap);
            }
    
            @Override
            public void onBitmapFailed(Drawable drawable) {
                Log.d("DEBUG", "onBitmapFailed");
            }
    
            @Override
            public void onPrepareLoad(Drawable drawable) {
                Log.d("DEBUG", "onPrepareLoad");
            }
        };
        Picasso.with(this).load(wallpaper.getMain_image()).into(mTarget);
        cropImageView.setTag(mTarget);
    

    Note:cropImageView is ImageView

    0 讨论(0)
提交回复
热议问题