Java 如何使用其中一个属性值在Firebase的同一个表中获取另一个属性值

Java 如何使用其中一个属性值在Firebase的同一个表中获取另一个属性值,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,用户预约后,属性(用户id、日期、时间)存储在预约表中,治疗师推送id作为父节点(以便于检索特定医生的预约) 现在,在用户界面中,我需要使用用户id获取所有属性。有人知道怎么做吗 这是我的数据库结构 这是我自己的代码 a=new ArrayList<AppointmentObject>(); databaseReference= FirebaseDatabase.getInstance().getReference(); databaseReference.addValueEve

用户预约后,属性(用户id、日期、时间)存储在预约表中,治疗师推送id作为父节点(以便于检索特定医生的预约)

现在,在用户界面中,我需要使用用户id获取所有属性。有人知道怎么做吗

这是我的数据库结构

这是我自己的代码

a=new ArrayList<AppointmentObject>();

databaseReference= FirebaseDatabase.getInstance().getReference();
databaseReference.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        //to get current log in user id
        String userid1 = FirebaseAuth.getInstance().getCurrentUser().getUid();

        for(DataSnapshot dataSnapshot1: dataSnapshot.child("appointment").getChildren()) {

            //if the userid stored is same as user id, it will be added to arraylist
            if(dataSnapshot1.getValue(AppointmentObject.class).getUserid().equals(userid1)){
                AppointmentObject thera= dataSnapshot1.getValue(AppointmentObject.class);
                a.add(thera);
            }
        }

        adapter=new MyRecyclerviewPAppointment(MainActivityPAppointment.this, a);
        rv.setAdapter(adapter);
    }

a=newarraylist();
databaseReference=FirebaseDatabase.getInstance().getReference();
databaseReference.addValueEventListener(新的ValueEventListener(){
@凌驾
public void onDataChange(@NonNull DataSnapshot DataSnapshot){
//获取当前登录用户id的步骤
字符串userid1=FirebaseAuth.getInstance().getCurrentUser().getUid();
对于(DataSnapshot dataSnapshot1:DataSnapshot.child(“约会”).getChildren()){
//如果存储的用户id与用户id相同,则会将其添加到arraylist中
if(dataSnapshot1.getValue(AppointmentObject.class).getUserid().equals(userid1)){
AppointmentObject thera=dataSnapshot1.getValue(AppointmentObject.class);
a、 添加(thera);
}
}
适配器=新的MyRecycleServiceWPAppointment(mainActivityAppointment.this,a);
rv.设置适配器(适配器);
}
然而,这似乎是一个错误


您的NullPointerException来自此行

if(dataSnapshot1.getValue(AppointmentObject.class).getUserid().equals(userid1)){
其中一个字段为null
dataSnapshot1、dataSnapshot1.getValue()、dataSnapshot1.getValue().getUserid()

为确保您的代码将编译为反向比较顺序:

if(userid1.equals(dataSnapshot1.getValue(AppointmentObject.class).getUserid()){

对于未来,请将所有文本内容包含为文本(无屏幕截图),以使其可在可重复使用的情况下进行搜索。对于数据库JSON,您可以通过单击溢出菜单中的“导出JSON”链接获得此信息(⠇) 在您的电脑上。另请参阅