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
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);
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