title: Accessing the children of a node using a query
body: <p>This is my database structure on firebase Realtime database:</p>
  
  <p><a href="https://i.stack.imgur.com/uyNCE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uyNCE.png" alt="enter image description here"></a></p>
  
  <p>I am trying to access the data under the last uploaded session, which in this case is <strong>Session9</strong> and access the sensor readings taken at a specific time.</p>
  
  <p>I have queried the database to give me the last node under <strong>data</strong> and added a <strong>ListenerForSingleValueEvent</strong>, at this location i am getting a key in <strong>keys</strong> List as <strong>session9</strong> (only one item) through the following:</p>
  
  <pre><code>Query lastSession = dbref.child("data").limitToLast(1);
   lastSession.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              for (DataSnapshot keyNode : dataSnapshot.getChildren()){
                  keys.add(keyNode.getKey());
                  Reading reading = node.getValue(Reading.class);
                  readings.add(reading);
                  textView.append(reading.getTemperature());
              } 
          }
     }
  </code></pre>
  
  <p>appending the temperature throws this error:</p>
  
  <pre><code>Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
  </code></pre>
  
  <p>readings is an arraylist of Reading class 
  keys is a list of Strings for storing the keys for example "00:00:06"</p>
  
  <p>I am making some mistake and cannot access the data that i want to add to readings list. </p>
  
  <pre><code>public class Reading {
  
  private String Date;
  private String Time;
  private String Humidity;
  private String Temperature;
  private int Sound;
  
  public Reading(){
  
  }
  </code></pre>