제목과 같은 오류가 났는데 실제 오류는
holder.mImgNew.setVisibility(isRead ? View.GONE : View.VISIBLE);
이 부분에서 났습니다. 검색을 좀 해봤는데 view 인스턴스화가 안되었다고 하는데 잘 모르겠네요..
글자수 제한 때문에 코드 전체를 입력 할 수 없어서 몇몇 코드는 제거 했습니다.
public class HomeRecyclerAdapter extends RecyclerView.Adapter<HomeRecyclerAdapter.ViewHolder> {
private static final String TAG = "HomeRecyclerAdapter";
private int itemLayout;
private Context context;
private ArrayList<NoticeItem> dataList;
private int LIST_SIZE;
public HomeRecyclerAdapter(Context context, int itemLayout) {
this.context = context;
this.itemLayout = itemLayout;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
boolean isRead = data.isRead();
holder.mImgNew.setVisibility(isRead ? View.GONE : View.VISIBLE);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return LIST_SIZE;
}
static class ViewHolder extends RecyclerView.ViewHolder {
private LinearLayout mItemBase;
private ImageView mImgNew;
private TextView mTxtTitle;
private TextView mTxtWriter;
private TextView mTxtTimeStamp;
ViewHolder(View itemView) {
super(itemView);
mItemBase = itemView.findViewById(R.id.itemBase);
mImgNew = itemView.findViewById(R.id.imgNew);
mTxtTitle = itemView.findViewById(R.id.txtTitle);
mTxtWriter = itemView.findViewById(R.id.txtWriter);
mTxtTimeStamp = itemView.findViewById(R.id.txtTimeStamp);
}
}
}