毕加索上下文==空问题 [英] Picasso context==null issue
本文介绍了毕加索上下文==空问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在crashlytics中遇到以下崩溃:
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
指的是:
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);
}
});
以上在我的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.
问题:
有人遇到这个问题吗?您是怎么解决的?
Has anyone experience this issue and what did you do to resolve it?
推荐答案
您需要初始化Picasso的单例实例.将此代码放在您的Application类的onCreate()方法中:
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());
这篇关于毕加索上下文==空问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文