ClassA
ClassA

Reputation: 2660

Picasso context==null issue

I'm getting the following crash in crashlytics:

Fatal Exception: java.lang.IllegalStateException: context == null
   at com.squareup.picasso.Picasso.get(Picasso.java:681)
   at com.package.name.Recycler.RecyclerVideoAdapter.onBindViewHolder(RecyclerVideoAdapter.java:435)

RecyclerVideoAdapter.java:435 is referring to:

Picasso.get().load(category.get(position).getImage()).noFade().tag("tag").resize(100, 100).centerCrop().networkPolicy(NetworkPolicy.OFFLINE).placeholder(R.drawable.image_placeholder).into(holder.img, new Callback() {
    @Override
    public void onSuccess() {
        //Success
    }

    @Override
    public void onError(Exception e) {
        Picasso.get().load(category.get(position).getImage()).noFade().resize(100, 100).centerCrop().memoryPolicy(MemoryPolicy.NO_CACHE).placeholder(R.drawable.image_placeholder).into(holder.img);
    }
});

The above is being called inside my onBindViewHolder


I have seen this issue being posted here, but I can't find a solution to this.

I think it's also worth mentioning that this issue is intermitted.


Question:

Has anyone experience this issue and what did you do to resolve it?

Upvotes: 1

Views: 752

Answers (1)

Alexei Artsimovich
Alexei Artsimovich

Reputation: 1184

You need to initialize your Picasso's singleton instance. Put this code in your Application class onCreate() method:

Picasso.setSingletonInstance(
                new Picasso.Builder(this)
                        // additional settings
                        .build());

Upvotes: 3

Related Questions