无法触发addListenerForSingleValueEvent

时间:2017-12-06 18:01:04

标签: android firebase firebase-realtime-database

下面有一段代码。我不知道为什么无法触发onDataChange。因此,对象singleChildSummary为null。

>ChildSummary singleChildSummary;
>DatabaseReference childSummaryRef = getChildDatabaseReference().child(id);
>     childSummaryRef.addListenerForSingleValueEvent(new ValueEventListener() {
>                 @Override
>                 public void onDataChange(DataSnapshot dataSnapshot) {
>                     singleChildSummary = dataSnapshot.getValue(ChildSummary.class);
 >                 }
>     
>                 @Override
>                 public void onCancelled(DatabaseError error) {
>                     // Failed to read value
>     //                Log.w(TAG, "Failed to read value.", error.toException());
>                 }
>             });

1 个答案:

答案 0 :(得分:0)

如果getValue()返回null“如果此位置没有数据”,则根据API documentation

相关问题