title: Set image from drawable to recyclerview
body: <p>I want to implement RecyclerView in bottom navigation fragment that contains CardViews with a TextView and an ImageView. I also have an onClickListener on every card that open new activity. but my recyclerview don't show anything and gives null point exception <a href="https://i.stack.imgur.com/24acS.png" rel="noreferrer">Logcat</a>.I don't know what I am missing here. </p>
  
  <p><strong>Model Class</strong></p>
  
  <pre><code>   class Data {
  
  public int imageId;
  public String txt;
  
  Data( int imageId, String text) {
  
      this.imageId = imageId;
      this.txt = text;
  }
  }
  </code></pre>
  
  <p><strong>RecyclerView Adapter</strong></p>
  
  <pre><code>    public class RecyclerViewAdapter  extends RecyclerView.Adapter&lt;RecyclerViewAdapter.MyViewHolder&gt; {
  List&lt;Data&gt; data ;
  Context context;
  
  public RecyclerViewAdapter(Context context, ArrayList&lt;Data&gt;data) {
      this.context = context;
      this.data = data;
  }
  
      public static class MyViewHolder extends RecyclerView.ViewHolder{
  
          public CardView mCardView;
          public TextView mTextView;
          public ImageView imageView;
  
          public MyViewHolder(View v){
              super(v);
  
              mCardView = (CardView) v.findViewById(R.id.cardview1);
              mTextView = (TextView) v.findViewById(R.id.tv_text);
              imageView = (ImageView) v.findViewById(R.id.iv_image);
  
          }
      }
  
      @Override
      public RecyclerViewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_items, parent, false);
          MyViewHolder vh = new MyViewHolder(v);
          return vh;
      }
  
      @Override
      public void onBindViewHolder(final MyViewHolder holder, int position){
  
          Data all = data.get(position);
          holder.mTextView.setText(all.txt);
          holder.imageView.setImageResource(all.imageId);
          holder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  int position = holder.getAdapterPosition();
                  final Intent intent;
                  if (position == 0){
                      intent =  new Intent(context, ShowDetails.class);
                  } else if (position == 1){
                      intent =  new Intent(context, AllDetails.class);
                  } else {
                      intent =  new Intent(context, RecentDetails.class);
                  }
                  context.startActivity(intent);
              }
          });
      }
  
  @Override
  public int getItemCount()
      {
          return data.size();
      }
   }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>     RecyclerView recyclerView;
  RecyclerView.Adapter adapter;
  private List&lt;Data&gt; data;
  
  public StatusFragment() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      // Inflate the layout for this fragment
      View rootView = inflater.inflate(R.layout.fragment_status, container, false);
  
      recyclerView = rootView.findViewById(R.id.recyclerView);
      recyclerView.setHasFixedSize(true);
      ArrayList&lt;Data&gt; data= new ArrayList&lt;&gt;();
  
      data.add(new Data( R.drawable.bg, "Image 1"));
      data.add(new Data( R.drawable.bg, "Image 2"));
      data.add(new Data( R.drawable.bg, "Image 3"));
      data.add(new Data( R.drawable.bg, "Image 1"));
      data.add(new Data( R.drawable.bg, "Image 2"));
      data.add(new Data( R.drawable.bg, "Image 3"));
      data.add(new Data( R.drawable.bg, "Image 1"));
      data.add(new Data( R.drawable.bg, "Image 2"));
      data.add(new Data( R.drawable.bg, "Image 3"));
  
      recyclerView.setAdapter(adapter);
      adapter.notifyDataSetChanged();
      LinearLayoutManager llm = new LinearLayoutManager(getActivity());
      recyclerView.setLayoutManager(llm);
      return  rootView;
  }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yr2uS.png" rel="noreferrer">ScreenShot</a></p>