title: Android Firebase retrieve child of child
body: <p>I'm trying to retrieve data from Firebase.
  The name inside Info</p>
  
  <p>This is my firebase tree.</p>
  
  <p><a href="https://i.stack.imgur.com/Y2hs0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y2hs0.jpg" alt="enter image description here"></a></p>
  
  <p>I've already done this</p>
  
  <pre><code>Firebase ref = new Firebase("https://link.firebaseio.com/Users/xxxxxxxx/Categories/drinks/");
  </code></pre>
  
  <p>Then I've created my listener</p>
  
  <pre><code>    ref.addChildEventListener(new ChildEventListener() {
                  @Override
                  public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                      Log.e("TOTAL ITEM " ,""+ dataSnapshot.getChildrenCount());
  
                      for (DataSnapshot eventSnapshot : dataSnapshot.getChildren()) {
                          //Item_Get_List newPost = eventSnapshot.child("Info").getValue(Item_Get_List.class);
                          System.out.println("GetChildren: "+eventSnapshot.child("Info"));
                          System.out.println("details: "+eventSnapshot.child("Info").getValue());
  
                      }
  </code></pre>
  
  <p>I got this in the console:</p>
  
  <pre><code>E/TOTAL ITEM: 2
  I/System.out: GetChildren: DataSnapshot { key = Info, value = null }
  I/System.out: details: null
  I/System.out: GetChildren: DataSnapshot { key = Info, value = null }
  I/System.out: details: null
  E/TOTAL ITEM: 2
  I/System.out: GetChildren: DataSnapshot { key = Info, value = null }
  I/System.out: details: null
  I/System.out: GetChildren: DataSnapshot { key = Info, value = null }
  I/System.out: details: null
  E/TOTAL ITEM: 1
  I/System.out: GetChildren: DataSnapshot { key = Info, value = {name=Pierre} }
  I/System.out: details: {name=Pierre}
  </code></pre>
  
  <p>But if I want to do</p>
  
  <pre><code>Item_Get_List newPost = eventSnapshot.child("Info").getValue(Item_Get_List.class);
  System.out.println("Name: "+newPost.getName());
  </code></pre>
  
  <p>I've got this error</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.app.pierre.myapp.Item_Get_List.getName()' on a null object reference
  </code></pre>
  
  <p>My Item_Get_list class is as follow:</p>
  
  <pre><code>public class Item_Get_List {
      private String name;
  
      public Item_Get_List(){
  
      }
  
      public Item_Get_List(String name){
          this.name = name;
  
      }
  
      public String getName(){
          return name;
      }
  }
  </code></pre>
  
  <p>What I have done wrong ??</p>
  
  <p>Thanks in advance</p>
  
  <hr>
  
  <p><strong>UPDATE</strong> 
  I found one temporary solution by doing</p>
  
  <pre><code>if(eventSnapshot.child("Info").getValue() != null){
                          System.out.println("Name: "+newPost.getName());
                      }
  </code></pre>
  
  <p>But that's just temporary, because I know i'm doing something wrong here. =(</p>