0

Lets say i have two model classes.

class School {
  ArrayList<Students> students;
  public ArrayList<Students> getStudents() {
   return students;
  }      

}

class Students {
  String studentName;
  public String getStudent() {
    return studentName;
  }
}

This is how i store the data: enter image description here

How would i go by retrieving the students? I've tried this, but it does not work.

mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            School s1 = datasnapshot.getValue(School.class)
            s1.getStudents();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
AL.
  • 36,815
  • 10
  • 142
  • 281
kensil
  • 126
  • 1
  • 6
  • 15
  • Have you made sure that myRef points exactly where you want it to be? – Ibrahim Ali Khan Apr 02 '17 at 14:55
  • sout(mRef) prints out firebase_url/school, so yes. Is the code above supposed to work? – kensil Apr 02 '17 at 15:01
  • 1
    Have you tried using `Hashmap someVariable` and then use `somevariable.getValue()` Try [this](http://stackoverflow.com/questions/30933328/how-to-convert-firebase-data-to-java-object) if above does not work – Firoz Memon Apr 02 '17 at 15:11

0 Answers0