title: Passing variable(position) from onBindViewHolder to ViewHolder class
body: <p>I am trying to pass a String (<code>userID</code>) from the <code>onBindViewHolder</code> to my <code>ViewHolder</code> class. The reason behind this is that I need the position to allocate the correct postID. This postID is used in the ViewHolder as a reference to set up a Firebase <code>valueEventListener</code>. However, when running the app I get a <code>NullPointerException</code> on the postID. Is this due to synchronization? Is the  <code>valueEventListener</code> called before postID is set?</p>
  
  <pre><code>public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      final PostViewHolder holder1 = (PostViewHolder) holder;
      holder1.postID = getPostId(position)
  
      //...
  }
  
  //...
  
  public class PostViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
  
      private DatabaseReference mNoOfLikesRef;
      public String postID;
      //...
  
      public PostViewHolder(View itemView, postClickListener listener){
          super(itemView);
  
          //This line causes the NullPointerException on postID
          mNoOfLikesRef = FirebaseDatabase.getInstance().getReference().child("likes").child(postID);
          ValueEventListener valueEventListener = new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  //...
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
              }
  
          };
          mNoOfLikesRef.addListenerForSingleValueEvent(valueEventListener);
  
      }
  </code></pre>