0
我试图获取Firebase数据库中各节的名称并将其添加到arraylist,但它只返回null。在5节点深度系统中检索第3个节点
mSectionReference = database.getReference().child("/apartments/").child("/B3/").child("/sections/");
ValueEventListener sectionListner = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("sections", "onDataChange");
if (dataSnapshot.exists()) {
Log.d("sections", "snapshot exists");
for (DataSnapshot sectionSnapshot : dataSnapshot.getChildren()) {
if (sectionSnapshot != null) {
Section section = sectionSnapshot.getValue(Section.class);
Log.d("sections", "Section created: " + section.getName());
} else
Log.d("sections", "sections null");
}
}
}
@Override
public void onCancelled(DatabaseError error) {
Log.w("failedSnap", "Failed to read value.", error.toException());
}
};
mSectionReference.addValueEventListener(sectionListner);
这是logcat的结果:
onDataChange
snapshot exists
Section created: null
Section created: null
include部分对象实现。 –