title: FirebaseRecyclerAdapter inside FirebaseRecyclerAdapter
body: <p>I'm building an events app and this is my cards mockup for each event:</p>
  
  <p><a href="https://i.stack.imgur.com/2wirW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2wirW.png" alt="enter image description here"></a></p>
  
  <p>Now this is my events data from my database. I have an <strong>"events"</strong> node (which contains each event item) and an <strong>"events-users"</strong> node (which contains each user item who is attending the event).</p>
  
  <p><a href="https://i.stack.imgur.com/daWLu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/daWLu.jpg" alt="enter image description here"></a></p>
  
  <p>To get the basic events item (image and name) I have a FirebaseRecyclerAdapter and it works good:</p>
  
  <pre><code>/**** EVENTS  EVENTS  EVENTS  EVENTS ****/
  // Inflates events
  RecyclerView mEventsRecyclerView = (RecyclerView) findViewById(R.id.activity_zone_events_recyclerview);
  mEventsRecyclerView.setLayoutManager(new GridLayoutManager(ZoneActivity.this, 1));
  DatabaseReference events = fDatabaseRoot.child("events");
  mEventsAdapter = new FirebaseRecyclerAdapter&lt;EventItem, EventItemHolder&gt;(EventItem.class, R.layout.item_event, EventItemHolder.class, events) {
      @Override
      protected void populateViewHolder(final EventItemHolder eventItemHolder, final EventItem event, final int position) {
  
          // Sets event image
          eventItemHolder.setEventImage(event.getEventImage());
  
          // Sets event name
          eventItemHolder.setEventName(event.getEventName());
  
          // Sets event OnClickListener
          eventItemHolder.eventCard.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  // Opens EventActivity
                  Intent eventActivity = new Intent(ZoneActivity.this, EventActivity.class);
                  startActivity(eventActivity);
              }
  
          }
      });
  
  };
  mEventsRecyclerView.setAdapter(mEventsAdapter);
  </code></pre>
  
  <p>The <strong>problem</strong> is that I don't know how to get the users items (attendees) inside every card.
  I tried by initializing another FirebaseRecyclerAdapter inside the FirebaseRecyclerAdapter I made but the app breaks when I open the corresponding activity... This is what I tried:</p>
  
  <pre><code>/**** EVENTS  EVENTS  EVENTS  EVENTS ****/
  // Inflates events
  RecyclerView mEventsRecyclerView = (RecyclerView) findViewById(R.id.activity_zone_events_recyclerview);
  mEventsRecyclerView.setLayoutManager(new GridLayoutManager(ZoneActivity.this, 1));
  DatabaseReference events = fDatabaseRoot.child("events");
  mEventsAdapter = new FirebaseRecyclerAdapter&lt;EventItem, EventItemHolder&gt;(EventItem.class, R.layout.item_event, EventItemHolder.class, events) {
      @Override
      protected void populateViewHolder(final EventItemHolder eventItemHolder, final EventItem event, final int position) {
  
          // Sets event image
          eventItemHolder.setEventImage(event.getEventImage());
  
          // Sets event name
          eventItemHolder.setEventName(event.getEventName());
  
          // Sets event OnClickListener
          eventItemHolder.eventCard.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  // Opens EventActivity
                  Intent eventActivity = new Intent(ZoneActivity.this, EventActivity.class);
                  startActivity(eventActivity);
              }
  
          /**** EVENT-ATTENDEES  EVENT-ATTENDEES  EVENT-ATTENDEES  EVENT-ATTENDEES ****/
          // Inflates event's attendees
          RecyclerView mAttendeesRecyclerView = (RecyclerView) findViewById(R.id.item_event_attendees_recyclerview);
          mAttendeesRecyclerView.setLayoutManager(new GridLayoutManager(ZoneActivity.this, 1));
          mAttendeesAdapter = new FirebaseRecyclerAdapter&lt;UserItem, UserItemHolder&gt;(UserItem.class, R.layout.item_user, UserItemHolder.class, fDatabaseRoot.child("zones-events").child(zoneKey)) {
              @Override
              protected void populateViewHolder(final UserItemHolder userItemHolder, final UserItem user, final int position) {
  
                  // Sets attendee image
                  userItemHolder.setUserImage(user.getUserImage());
  
              }
  
          };
          mAttendeesRecyclerView.setAdapter(mAttendeesAdapter);
  
      }
  
  };
  mEventsRecyclerView.setAdapter(mEventsAdapter);
  </code></pre>
  
  <p>And this is the <strong>error</strong>:</p>
  
  <pre><code>02-27 19:18:53.783 1050-1050/? E/UncaughtException:  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
                                                      at com.whatudu.whatudu.ZoneActivity$2$1$1.populateViewHolder(ZoneActivity.java:208)
                                                      at com.whatudu.whatudu.ZoneActivity$2$1$1.populateViewHolder(ZoneActivity.java:141)
                                                      at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:184)
                                                      at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5825)
                                                      at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5858)
                                                      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5094)
                                                      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
                                                      at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
                                                      at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:541)
                                                      at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
                                                      at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
                                                      at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
                                                      at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
                                                      at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2843)
  </code></pre>
  
  <p>Any kind of help or tip (if someone has done this before) will be really appreciated! I know this is possible, I just don't know how to do it! :( </p>
  
  <p>Thank you very much in advance.</p>
  
  <p>P.S. GridLayoutManager is selected as the layout style because that's what I was doing previously.</p>