我想从firebase数据库中获取数据,我使用了valueEventListner Datasnapshot包含数据,但是当它映射到User对象时,object会将所有属性显示为null。请建议解决方案
mDatabaseReference =mFireBaseDatabase.getReference(table_name);
mDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.v(TAG,"user snap shot count:"+dataSnapshot.getChildrenCount());
// users is arraylist
users.clear();
for(DataSnapshot usersnapshot : dataSnapshot.getChildren())
{
Log.v(TAG,"Profile user snap:"+usersnapshot.toString());
User user = usersnapshot.getValue(User.class);
Log.v(TAG,"user data:"+user.toString());
}
}
答案 0 :(得分:0)
当您插入时间通过用户对象的数据时,如下所示..
laravel vhost(virtual host)
然后您的代码确定我认为当您读取时间定义firebase实例的数据时..
User user = new User(name, email, pwd);
mFirebaseDatabase.child(name).setValue(user);