【发布时间】:2018-01-14 04:08:24
【问题描述】:
我有以下结构
root
-sections
-section1
-student1
-GPA
-lastname
-student2
-GPA
-lastname
-section2
-student1
-GPA
-lastname
我需要获得用户想要的学生的 GPA。
我正在这样做:
String student = student.getText().toString(); //Student1/Student2 entered
String section = section.getText().toString();
//This is Section1, Student1, say (obtained from EditText)...
那我在做
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) {}
});
我得到 0.0 作为结果。
我哪里错了?
【问题讨论】:
-
这部分学生的GPA可能是0.0。您是否调试过您的应用程序并了解它为什么会打印当前结果?
-
是的,我已经在 LOG 和 textView 中打印了值(以防万一)。这就是我知道值是 0.0
-
在应用程序上打印为 0.0 之前,该学生在 firebase 数据库中该部分的 GPA 是多少?
-
它是一个介于 3 和 4 之间的值(例如:3.1、3.75、4.0 等)
-
也许您需要在问题中包含更多代码。从我所见,您的代码看起来不错。
标签: java android firebase firebase-realtime-database