title: How to get child value for my RecyclerView when use Firebase database?
body: <p>I use <code>dataSnapshot.getValue(ChatItem.class);</code> to save value that is <code>name</code> and <code>msg</code> from FirebaseDatabase.</p>
  
  <p>When I use <code>firstRoot.addChildEventListener</code> my textRight of recyclerView value is empty, so I try to use <code>addChildEventListener</code> in different root that is <code>secondRoot.addChildEventListener</code> and <code>thirdRoot.addChildEventListener</code>, it will cause crash.</p>
  
  <p>I don't know another way to get it. Can someone teach me how to finish it?
   Thanks in advance.</p>
  
  <p>Here is my  ChatRoom class for RecyclerView:</p>
  
  <pre><code>public class ChatRoom extends AppCompatActivity {
  
      private String roomName, userName;
  
      private Button sendMessage;
      private EditText typeMessage;
      private String temp_key;
  
      private DatabaseReference firstRoot;
      private DatabaseReference secondRoot;
      private DatabaseReference thirdRoot;
  
      private RecyclerView recyclerChat;
      private ArrayList&lt;ChatItem&gt; listData = new ArrayList&lt;&gt;();
      private RecyclerChatAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_chat_room);
  
          initViews();
  
          roomName = getIntent().getExtras().getString("room_name");
          userName = getIntent().getExtras().getString("userName");
  
          setTitle("Chat Name:" + roomName);
  
          firstRoot = FirebaseDatabase.getInstance().getReference().child("ChatGroup");//specify first child
  
          sendMessage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  secondRoot = firstRoot.child(roomName);
  
                  Map&lt;String, Object&gt; mapKey = new HashMap&lt;&gt;();
                  temp_key = firstRoot.push().getKey();//create key control json tree
                  firstRoot.updateChildren(mapKey);
  
  
                  Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
                  map.put("name", userName);
                  map.put("msg", typeMessage.getText().toString());
  
                  thirdRoot = secondRoot.child(temp_key);
                  thirdRoot.updateChildren(map);
  
                  typeMessage.setText("");
              }
          });
  
          firstRoot.addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                  ChatItem chatItem = dataSnapshot.getValue(ChatItem.class);//i save value to my java bean class
  
                  listData.add(chatItem);
                  recyclerChat.scrollToPosition(adapter.getItemCount() - 1);//just let the latest data below
                  adapter.notifyDataSetChanged();
              }
  
              @Override
              public void onChildChanged(DataSnapshot dataSnapshot, String s) {
  
              }
  
              @Override
              public void onChildRemoved(DataSnapshot dataSnapshot) {
  
              }
  
              @Override
              public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
  
  
          LinearLayoutManager manager = new LinearLayoutManager(this);
          //        GridLayoutManager gridLayoutManager=new GridLayoutManager(this,2);
          manager.setOrientation(LinearLayoutManager.VERTICAL);
          recyclerChat.setLayoutManager(manager);
  
          adapter = new RecyclerChatAdapter(this, listData);
          recyclerChat.setAdapter(adapter);
          adapter.notifyDataSetChanged();
      }
  
      private void initViews() {
          sendMessage = (Button) findViewById(R.id.sendMessage);
          typeMessage = (EditText) findViewById(R.id.typeMessage);
          recyclerChat = (RecyclerView) findViewById(R.id.recyclerChat);
      }
  }
  </code></pre>
  
  <p>My javabean:</p>
  
  <pre><code>public class ChatItem {
      private String name;
      private String msg;
  
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getMsg() {
          return msg;
      }
  
      public void setMsg(String msg) {
          this.msg = msg;
      }
  
  }
  </code></pre>
  
  <p>My RecyclerViewAdapter about onBindViewHolder:</p>
  
  <pre><code>@Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          holder.textRight.setText(itemList.get(position).getMsg());
      }
  </code></pre>
  
  <p>Here is my json tree:
  <a href="https://i.stack.imgur.com/z3A1p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z3A1p.png" alt="enter image description here"></a></p>
  
  <p>I try to use constructor for my javabean , it's till no working:</p>
  
  <pre><code>public ChatItem(){
  }
  
  public ChatItem(String name, String msg) {
      this.name = name;
      this.msg = msg;
  } 
  </code></pre>
  
  <p>I had set permission too:</p>
  
  <pre><code> &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>My question is <code>holder.textRight.setText(itemList.get(position).getMsg());</code> is null , i can't get it for my recyclerView</p>
  
  <p>I use <code>ChatItem chatItem = dataSnapshot.getValue(ChatItem.class);</code> works like this json tree:
  <a href="https://i.stack.imgur.com/r8iJB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r8iJB.png" alt="enter image description here"></a></p>