Firebase query by time range [android]
<p>I need to look for the subject that matches the current time. For example, current time is 1:30. So if I'll run a query with Firebase, it should return the subject Math.  </p>

<p>Here's my JSON where "2012123458" is a faculty_id.</p>

<pre><code>schedule:{
     "2012123458" : {
  "Saturday" : {
    "-K8j0EkwmWjj3vMqB2d3" : {
      "classroom" : "Lab 3",
      "subject" : "Science",
      "time_end" : "2:00",
      "time_start" : "0:00"
    },
    "asdasdasd" : {
      "classroom" : "Lab 6",
      "subject" : "PE",
      "time_end" : "18:00",
      "time_start" : "17:00"
    },
    "qweqweqweqwe" : {
      "classroom" : "Lab 5",
      "subject" : "PE",
      "time_end" : "11:00",
      "time_start" : "9:00"
    }
  }
}
}
</code></pre>

<p>I've tried this but returns a NullPointerException</p>

<pre><code>       gridView.setAdapter(listFaculty);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
            FacultyList faculty = (FacultyList) parent.getItemAtPosition(position);
            String faculty_id = faculty.getID();


            //Display schedule in a Dialog box
            final Dialog dialog = new Dialog(Faculty.this);
            dialog.setContentView(R.layout.dialog_sched);


           Firebase ref = new Firebase("https://infotrack.firebaseio.com/schedule/"+faculty_id+"/Saturday");
           ref.addListenerForSingleValueEvent(new ValueEventListener() {
               @Override
               public void onDataChange(DataSnapshot dataSnapshot) {
                   for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){


                       schedule sched = postSnapshot.getValue(schedule.class);
                       TextView subject = (TextView) dialog.findViewById(R.id.txtSubject);
                       TextView time = (TextView) dialog.findViewById(R.id.txtTime);
                       TextView classroom = (TextView) dialog.findViewById(R.id.txtClassroom);

                       if(sched != null) {


                           if (checkTime(sched.getTime_start(), sched.getTime_end())){
                               Log.e("test", "x");

                                   Log.e("test", "" + dataSnapshot.getChildrenCount());

                                   Log.e("test", postSnapshot.getValue().toString());
                                   Log.e("test", "0");

                                   subject.setText(sched.getSubject());
                                   Log.e("test", sched.getSubject());


                                   time.setText(sched.getTime_start() + " - " + sched.getTime_end());
                                   Log.e("test", "2");


                                   classroom.setText(sched.getClassroom());
                               }

                        }  
                       else { 
                           Log.e("test", "null");
                       }

                   }
               }

               @Override
               public void onCancelled(FirebaseError firebaseError) {
                   Log.d("sched", firebaseError.getMessage());
               }
           });
           dialog.show();



       }
   });
</code></pre>

<p>schedule class:</p>

<pre><code>public class schedule {

  private String subject;
  private String time_end;
  private String time_start;

  public schedule(){ }

  public schedule(String subject, String time_end, String time_start){

    this.subject = subject;
    this.time_end = time_end;
    this.time_start = time_start;

  }

  public String getSubject(){
    return subject;
  }

  public String getTime_end(){
    return time_end;
  }

  public String getTime_start(){
    return time_start;
  }
}
</code></pre>

<p>UPDATE: 
The problem now is it does not work for some items on the grid view. It brings me back to my app's home screen after clicking on them. An empty dialog box appears for a short period then returns to the home screen.   </p>