2 qq 28186229 qq_28186229 于 2016.03.23 09:39 提问

第一次用RecyclerView,求大神帮忙看下适配器错误

图片说明
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class CourseListRecyclerViewAdapter extends RecyclerView.Adapter{
private List mList;
private Context mContext;
private LayoutInflater mInflater;

//构造方法
public CourseListRecyclerViewAdapter(Context context, List<SearchResult> mList) {
    this.mContext = context;
    this.mInflater = LayoutInflater.from(context);
    this.mList = mList;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = mInflater.inflate(R.layout.course_list_item, parent, false);
    MyViewHolder myViewHolder = new MyViewHolder(view);
    return myViewHolder;
}

@Override
public void onBindViewHolder(MyViewHolder myViewHolder, int position) {
    myViewHolder.textView.setText(mList.toString());
}

@Override
public int getItemCount() {
    return mList.size();
}

class MyViewHolder extends RecyclerView.ViewHolder {
    public TextView textView;

    public MyViewHolder(View view) {
        super(view);
        textView = (TextView) view.findViewById(R.id.course_list_textview);
    }
}

}

1个回答

bdmh
bdmh   Ds   Rxr 2016.03.23 09:42

第39行,空指针,调试,看看哪个对象没有创建

qq_28186229
qq_28186229 恩,谢谢
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!