title: Get ViewHolder for specific position - RecyclerView
body: <p>I need to get the viewholder for a specific position, but I get this error:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to read from field
    'android.view.View
    android.support.v7.widget.RecyclerView$ViewHolder.itemView' on a null
    object reference</p>
  </blockquote>
  
  <p>Here is my adaptor:</p>
  
  <pre><code>public class ConciergeAdapter extends RecyclerView.Adapter&lt;ConciergeAdapter.MyViewHolder&gt; {
  
      private Context context;
      private ArrayList&lt;String&gt; items;
  
      public class MyViewHolder extends RecyclerView.ViewHolder
      {
          public TextView text;
          public RelativeLayout maincon;
  
          public MyViewHolder(View view) {
              super(view);
              this.text = (TextView) view.findViewById(R.id.text);
              this.maincon = (RelativeLayout) view.findViewById(R.id.maincon);
          }
      }
  
      public ConciergeAdapter(Context context, ArrayList&lt;String&gt; items)
      {
          this.context = context;
          this.items = items;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
      {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.fragment_concierge_top_items, parent, false);
  
          return new MyViewHolder(itemView);
      }
  
  
      @Override
      public void onBindViewHolder(ConciergeAdapter.MyViewHolder holder, int position)
      {
          Random rnd = new Random();
          int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
          holder.maincon.setBackgroundColor(color);
      }
  
      @Override
      public int getItemCount() {
          return items.size();
      }
  }
  </code></pre>
  
  <p>And this is  the code where I am calling the adaptor and trying to get the ViewHolder:</p>
  
  <pre><code>final LinearLayoutManager layoutManager= new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL, false);
          mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
          mRecyclerView.setLayoutManager(layoutManager);
  
          ArrayList&lt;String&gt; itemslist = new ArrayList&lt;String&gt;();
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
          itemslist.add("1");
  
          ConciergeAdapter adapter = new ConciergeAdapter(getActivity(),itemslist);
          mRecyclerView.setAdapter(adapter);
  
          //RecyclerView.ViewHolder viewholder =  mRecyclerView.findViewHolderForAdapterPosition(1); 
  
          View holder = layoutManager.getChildAt(0);
  
          RelativeLayout middle = (RelativeLayout) holder.findViewById(R.id.maincon);
          middle.getLayoutParams().height = 200;
  </code></pre>