快照值返回空Firebase

时间:2020-08-13 16:36:32

标签: java android firebase firebase-realtime-database

我从firebase获得了一些图像ID,但是即使我100%确信数据存在并且键名正确,这也总是返回null,这是我的代码和firebase数据库:

select 
    Question,
    AnswerInt,
    AnswerText,
    CreatedTime,
    SurveyType,
    ResponseTypeDesc,
    CONCAT('LabelText', AnswerInt)LabelText
FROM
    dbo.WEBSITE_SURVEYS

Firebase Database

当我将其打印为String storeidd = getIntent().getStringExtra("storeid"); Query query = FirebaseDatabase.getInstance().getReference().child("Member").child(storeidd).child(childDataSnapshot.getKey()).child("proImages").orderByChild("ImageID").equalTo("1597332319044_0.null"); query.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if (snapshot.exists()){ System.out.println(snapshot.child("ImageID").getValue().toString()); // <- returns null itemArrayList.add(new ClassListItems(childDataSnapshot.child("proname").getValue().toString(),snapshot.child("ImageID").getValue().toString(),childDataSnapshot.child("proprice").getValue().toString(),childDataSnapshot.child("prodesc").getValue().toString())); myAppAdapter = new MyAppAdapter(itemArrayList, showProducts.this); listView21.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView21.setAdapter(myAppAdapter); } } @Override public void onCancelled(@NonNull DatabaseError error) { } }); 时 它给了我System.out.println(snapshot.getValue().toString()); 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您需要在快照中进行迭代才能获取数据:

public void onDataChange(DataSnapshot snapshot) {
    if (snapshot.exists()){
        for(DataSnapshot ds : snapshot.getChildren()){
            String imageID = ds.child("ImageID").getValue(String.class);
        }
    }
}