Firebase DataSnapshot.getValue()为null

我一直在这里查看SO中的其他错误,因为我的问题似乎仍然无法解决,因为我一直在获取Datasnapshot.getvalue()返回null ...

首先,我得到db-ref:

    private DatabaseReference f_database = FirebaseDatabase.getInstance().getReference().child("maps_data");

然后在活动中的OnCreate方法中添加一个侦听器:

        f_database.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(Datasnapshot datasnapshot) {
            if(datasnapshot.exists()){ <<<< Problem is here,value is null
                for(Datasnapshot snapshot:datasnapshot.getchildren()){
                    double lati = 0;
                    // Get UsersLocationFavorites object and use the values to update the UI
                    UsersLocationFavorites userLocFav = snapshot.getvalue(UsersLocationFavorites.class);

                    LatLng location = new LatLng(userLocFav.getFavoriteSpot().getLatitude(),userLocFav.getFavoriteSpot().getLongitude());
                    gmap.addMarker(new MarkerOptions().position(location).title("Old Marker"));
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

在我的Firebase数据库中查看以下信息:

Firebase DataSnapshot.getValue()为null

我已经仔细检查了拼写(“ maps_data”),在这里我发现了很多SO问题,在其中找不到适合我的问题。

任何人都可以看到,我做错了吗?

kewell1984 回答:Firebase DataSnapshot.getValue()为null

您正在混合Firebase提供的数据库。

您显示的所有代码都在访问Firebase实时数据库。但是屏幕截图显示了Firestore中的数据。这些是完全不同的数据库产品。如果您想从Firestore中读取数据,则应改用Firestore SDK。

本文链接:https://www.f2er.com/2953367.html

大家都在问