Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Android Studio中的Firebase检索_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

从Android Studio中的Firebase检索

从Android Studio中的Firebase检索,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我的firebase数据库的结构如下所示: -Details -BNFJ3491 -Answer: "abc" -Name: "ABC" -Password:"cde" -Security Question: "rgrg" -User Type: "Student" -CBTV15873 -Answer: "abc" -Name: "ABC" -Pass

我的firebase数据库的结构如下所示:

-Details
    -BNFJ3491
        -Answer: "abc"
        -Name: "ABC"
        -Password:"cde"
        -Security Question: "rgrg"
        -User Type: "Student"
    -CBTV15873
        -Answer: "abc"
        -Name: "ABC"
        -Password:"cde"
        -Security Question: "rgrg"
        -User Type: "Student"
-Notices
    -B tech placement
        -Department: "Urja Mandir"
        -Matter: "Hello welcome to btech placement cell"

我不知道如何获取特定id的密码(如BNFJ3491)。datasnapshot将获取所有数据,但如何检索特定id的信息。

请使用以下代码:

Firebase ref=new Firebase("https://linkb-873e1.firebaseio.com/Details");
ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String password = dataSnapshot.child(-BNFJ3491).child("Password").getValue();
            }


            @Override
            public void onCancelled(FirebaseError firebaseError) {
                System.out.println("The read failed: " + firebaseError.getMessage());
            }

        });
您可以使用此代码

ref.child(userId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    String password = dataSnapshot.child("Password").getValue(String.class);
 }

@Override
public void onCancelled(DatabaseError databaseError) {}
});

谢谢你的帮助!
ref.child(userId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    String password = dataSnapshot.child("Password").getValue(String.class);
 }

@Override
public void onCancelled(DatabaseError databaseError) {}
});