Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
Java 如何在android中从firebase数据库的uid中获取/检索多个数据?_Java_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

Java 如何在android中从firebase数据库的uid中获取/检索多个数据?

Java 如何在android中从firebase数据库的uid中获取/检索多个数据?,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,如何使用以下代码从firebase获取数据? 成功登录后,我收到空指针异常 DatabaseReference mref = FirebaseDatabase.getInstance().getReference().child("/Users/Students") .child(FirebaseAuth.getInstance().getCurrentUser().getUid()); mref.addValueEventList

如何使用以下代码从firebase获取数据?
成功登录后,我收到空指针异常

DatabaseReference mref = FirebaseDatabase.getInstance().getReference().child("/Users/Students")
                    .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
            mref.addValueEventListener(new ValueEventListener() {
                @SuppressLint("SetTextI18n")
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    for (DataSnapshot ds : dataSnapshot.getChildren()){

                        email = ds.child("email").getValue().toString();
                        full_name = ds.child("full_name").getValue().toString();
                        roll_number = ds.child("roll_number").getValue().toString();
                        admission_id = ds.child("admission_id").getValue().toString();
                        phone_no = ds.child("phone_number").getValue().toString();
                        branch = ds.child("branch").getValue().toString();
                        year = ds.child("year").getValue().toString();
                        semester = ds.child("semester").getValue().toString();
                        section = ds.child("section").getValue().toString();
                        course = ds.child("course").getValue().toString();
                        batch = ds.child("batch").getValue().toString();
                        dob = ds.child("dob").getValue().toString();
                        address = ds.child("address").getValue().toString();
                    }

                }
我的Firebase数据库是:

移除以下各项:

 for (DataSnapshot ds : dataSnapshot.getChildren()){
因为您已经可以访问uid,所以不需要在直接子对象中循环来获取值

那么就这么做吧:

 public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                    email = dataSnapshot.child("email").getValue().toString();
                    full_name = dataSnapshot.child("full_name").getValue().toString();
                    roll_number = dataSnapshot.child("roll_number").getValue().toString();
                    admission_id = dataSnapshot.child("admission_id").getValue().toString();
                    phone_no = dataSnapshot.child("phone_number").getValue().toString();
                    branch = dataSnapshot.child("branch").getValue().toString();
                    year = dataSnapshot.child("year").getValue().toString();
                    semester = dataSnapshot.child("semester").getValue().toString();
                    section = dataSnapshot.child("section").getValue().toString();
                    course = dataSnapshot.child("course").getValue().toString();
                    batch = dataSnapshot.child("batch").getValue().toString();
                    dob = dataSnapshot.child("dob").getValue().toString();
                    address = dataSnapshot.child("address").getValue().toString();

通过记录或调试uid来检查您是否获得了uid。