Picasso context==null issue

点点圈 提交于 2019-12-11 05:24:55

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/56459099/picasso-context-null-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!