Get the kids from the fire base?
I have the following structure
root
-sections
-section1
-student1
-GPA
-lastname
-student2
-GPA
-lastname
-section2
-student1
-GPA
-lastname
I need to get the GPA of a desired student by the user.
I'm doing it:
String student = student.getText().toString(); //Student1/Student2 entered
String section = section.getText().toString();
//This is Section1, Student1, say (obtained from EditText)...
Then i do
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) {}
});
As a result, I get 0.0.
Where am I going wrong?
+3
source to share
1 answer
Typically, users need to be authenticated before they can read or write to the database. Have you disabled the rules in the console or have some users been logged in?
You can see the rules tab in this picture: https://www.novoda.com/blog/content/images/2016/06/Screenshot_20160621_174302.png
EDIT
The code seems fine, maybe there is something wrong with the "section" and "student" keys. You can test it using hardcoded strings.
0
source to share