Firebase在Android中为数据值返回null

时间:2016-09-12 23:52:46

标签: android json firebase firebase-realtime-database

所有data.getValue()都返回null。我可以让孩子钥匙返回罚款。我可以写firbase罚款。只是data.getValue因某些未知原因返回null。我有其他类使用完全相同的格式正常工作。

//method for retrieving info from firebase which has notifications
private void retrieveInfo(){
    Firebase ref = new Firebase("https://fitnectapp.firebaseio.com/");

    // Attach an listener to read the data at our posts reference
    ref.addChildEventListener(new ChildEventListener() {
        // Retrieve new posts as they are added to the database
        @Override
        public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
            getUpdates(snapshot);
        }
        @Override
        public void onChildRemoved(DataSnapshot snapshot) {
            getUpdates(snapshot);
        }
        @Override
        public void onChildChanged(DataSnapshot snapshot, String previousChildKey) {
            getUpdates(snapshot);
        }
        @Override
        public void onChildMoved(DataSnapshot snapshot, String previousChildKey) {
        }
        @Override
        public void onCancelled(FirebaseError firebaseError) {
        }
    });
}

//All data values returning null??
private void getUpdates(DataSnapshot ds) {
    if (ds.getKey().equals("notifications")) {
        for (DataSnapshot data : ds.getChildren()) {
            String user = sp.getString("username", null);
            Notification notification = data.getValue(Notification.class);
            if(notification.getNotifUser().equals(user)){
                String sender = notification.getNotifSender();
                String workout = notification.getNotifWorkout();
                String notificationTxt = sender + " has liked your workout, " + workout;
                notifications.add(notificationTxt);
            }

        }
    }
}

0 个答案:

没有答案