hey how to use context in get ,Searched a lot but not getting solution all solution are provided with .with()
//Have to use hear
public void setUserImage(String thumb_image, Context ctx) {
CircleImageView userImageView = mView.findViewById(R.id.single_user_image);
Picasso.get().load(thumb_image).placeholder(R.drawable.profile).into(userImageView);
}
//Populated from
viewHolder.setUserImage(model.getThumb_image(), getApplicationContext());
Please help
I think you don't need to use Context anymore. Someone please confirm.
I think the idea is to not need context but when trying to load a drawable into a 'Target' object, it throws an exception that context is null =/
You're right @c0dehunter Context is not used anymore.
@vshivam can you paste here the full logcat from the exception you're getting?
@rosariopfernandes This is it really:
java.lang.IllegalStateException: context == null
at com.squareup.picasso.Picasso.get(Picasso.java:681)
I believe Picasso can't get the context when you call it from a ViewHolder.
A workaround would be declaring and initializing userImageView in your ViewHolder class. This way you may remove your setUserImage() method.
And in your adapter you can simply call:
Picasso.get().load(model.getThumb_image()).placeholder(R.drawable.profile).into(viewHolder.userImageView);
@rosariopfernandes In my case, the load method is called in the onBindViewHolder method of a RecyclerView Adapter. The bitmap is loaded into a Target object so there is no ImageView involved.
This is what the call looks like:
Picasso.get().load(buttonImageURL).into(target);
@rosariopfernandes In my case, the
loadmethod is called in theonBindViewHoldermethod of aRecyclerViewAdapter. The bitmap is loaded into aTargetobject so there is no ImageView involved.This is what the call looks like:
Picasso.get().load(buttonImageURL).into(target);
Hi , i got this problem too, exception shows context == null;
and i think it's occured after i update androidX; before i update its working fine.
Did you resolve this problem? ^.^
@bladeofgod I got rid of Picasso and wrote my own thing instead.
Only really needed it for a very small use.
If you get back to Picasso 2.5.2 you can use the method .with() and pass a context.
@rosariopfernandes This is it really:
java.lang.IllegalStateException: context == null at com.squareup.picasso.Picasso.get(Picasso.java:681)
add this line "Picasso.setSingletonInstance(new Picasso.Builder(this).build());" at your Application.java file in onCreate.
Can confirm, initializing the Picasso in application class did the trick:
Most helpful comment
add this line "Picasso.setSingletonInstance(new Picasso.Builder(this).build());" at your Application.java file in onCreate.