get children from firebase?

Viewed 111

I have the following structure

root
    -sections
        -section1
            -student1
                -GPA
                -lastname
            -student2
                -GPA
                -lastname
        -section2
            -student1
                -GPA
                -lastname

I need to get GPA of the student desired by the user.

I am doing this:

String student = student.getText().toString(); //Student1/Student2 entered
String section = section.getText().toString();
    //This is Section1, Student1, say (obtained from EditText)...

Then I am doing

myref = FirebaseDatabase.getInstance().getReference().child("sections");
myref1 = myref.child(section).child(student).child("GPA");
myref1.addValueEventListener(new ValueEventListener() {
  public void onDataChange(DataSnapshot dataSnapshot) {
    String gpa = dataSnapshot.getValue().toString();
  }
  public void onCancelled(DatabaseError databaseError) {}
});

I am getting 0.0 as the result.

Where am I going wrong?

1 Answers
Related