我正在创建回收站视图,通过改造从Web服务器获取数据,当我想通过picasso获取图像时我的问题我有错误消息
java.lang.IllegalArgumentException: Context must not be null.
我不知道为什么context是null我在onBindViewHolder中添加picasso
我的适配器
public class myAdapter extends RecyclerView.Adapter<myAdapter.ViewHolder> {
private List<Listitem>listitems;
private Context context;
public myAdapter(List<Listitem> listitems, Context context) {
this.listitems = listitems;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Listitem listitem = listitems.get(position);
holder.textTitile.setText(listitem.getTitel());
holder.textDesc.setText(listitem.getDesc());
Picasso.with(context)
.load(listitem.getImageurl())
.placeholder(R.color.colorAccent)
.into(holder.movieThumbnail);
}
@Override
public int getItemCount() {
return listitems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView textTitile ;
public TextView textDesc;
public ImageView movieThumbnail;
public ViewHolder(View itemView) {
super(itemView);
textTitile=(TextView) itemView.findViewById(R.id.Titell);
textDesc=(TextView)itemView.findViewById(R.id.desc);
movieThumbnail = (ImageView) itemView.findViewById(R.id.movie_thumbnail);
}
}
}
答案 0 :(得分:0)
你的Context是null,你可以使用任何方式使用视图上下文ex:holder.itemView.getContext()
你可以检查你发送的不是空的,或者你可以使用打击方法。
所以你可以改为
awk 'function get_count(s, c, len) {
len=split(s,a,":"); while(len--) if(a[len]){ c++ }
return c
} BEGIN { FS=OFS="\t" }get_count($4) > 1 || get_count($5) > 1' file