Picasso Load Image Failed and App Crashing

后端 未结 2 1140
情深已故
情深已故 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);
    

提交回复
热议问题