Java Firebase数据库don';无法在Android中更新

Java Firebase数据库don';无法在Android中更新,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,我有一个android studio编码注册,数据库是firebase。当我输入要注册的数据时,firebase数据库中不会更新这些值 但是firebase身份验证已经更新 这是我注册的代码 public class DriverLogin extends AppCompatActivity { private EditText mEmail, mPassword; private Button mLogin, mRegistration; private Fir

我有一个android studio编码注册,数据库是firebase。当我输入要注册的数据时,firebase数据库中不会更新这些值

但是firebase身份验证已经更新

这是我注册的代码

public class DriverLogin extends AppCompatActivity {

    private EditText mEmail, mPassword;
    private Button mLogin, mRegistration;

    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener firebaseAuthListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_login);

        mAuth = FirebaseAuth.getInstance();

        firebaseAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                if (user != null){
                    Intent intent = new Intent(DriverLogin.this, MapsActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }
        };

        mEmail = (EditText) findViewById(R.id.email);
        mPassword = (EditText) findViewById(R.id.password);

        mLogin =  (Button) findViewById(R.id.Login);
        mRegistration =  (Button) findViewById(R.id.Registration);

        mRegistration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();

                mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLogin.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(!task.isSuccessful()){
                            Toast.makeText(DriverLogin.this, "Sign up Error!", Toast.LENGTH_SHORT).show();
                        }else {
                            String user_id = mAuth.getCurrentUser().getUid();
                            DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("Driver").child(user_id);
                            current_user_db.setValue(true);
                        }
                    }
                });
            }
        });
}
公共类DriverLogin扩展了AppCompative活动{
私人编辑文本mEmail,mPassword;
专用按钮登录、注册;
私人消防队;
私有FirebaseAuth.AuthStateListener firebaseAuthListener;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u driver\u login);
mAuth=FirebaseAuth.getInstance();
firebaseAuthListener=新的FirebaseAuth.AuthStateListener(){
@凌驾
AuthStateChanged上的公共void(@NonNull FirebaseAuth FirebaseAuth){
FirebaseUser=FirebaseAuth.getInstance().getCurrentUser();
如果(用户!=null){
Intent Intent=新Intent(DriverLogin.this,MapsActivity.class);
星触觉(意向);
完成();
回来
}
}
};
mEmail=(EditText)findViewById(R.id.email);
mPassword=(EditText)findViewById(R.id.password);
mLogin=(按钮)findviewbyd(R.id.Login);
mrRegistration=(按钮)findViewById(R.id.Registration);
mrRegistration.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
最后一个字符串email=mEmail.getText().toString();
最终字符串密码=mPassword.getText().toString();
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(DriverLogin.this,newonCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
如果(!task.issusccessful()){
Toast.makeText(DriverLogin.this,“注册错误!”,Toast.LENGTH\u SHORT.show();
}否则{
字符串user_id=mAuth.getCurrentUser().getUid();
DatabaseReference当前用户数据库=FirebaseDatabase.getInstance().getReference().child(“用户”).child(“驱动程序”).child(用户id);
当前用户设置值(真);
}
}
});
}
});
}

我认为这里的主要问题是,您对如何制作Firebase的数据库结构感到困惑

  • 转到您的
    Firebase控制台
    ,然后转到
    数据库
  • 将鼠标悬停在您的
    根目录下
    。在您的情况下,
    位驱动程序应用程序
    ,然后单击
    +
    。这是
    添加子项
  • 现在,我想你想用许多用户的
    UID
    来创建
    Driver
    。因此,只需键入
    Driver
    ,不带任何值。然后再次单击
    +
  • 现在我想这就是你想要你的
    用户id
  • 可能还有一些
    变量
    ,比如
    名称
    ,等等

  • 因此,基本上你不能将child添加到有
    值的东西中。在你的情况下,你的
    驱动程序有
    value=true
    ,它不能有child,也不会得到更新

    感谢所有帮助我解决问题的人

    我已经找到了答案,我正在发布它,希望将来有人能得到帮助

    firebase数据库规则必须设置为,如下所示

    {
      "rules": {
        ".read": "auth != null",
        ".write": "auth != null"
      }
    }
    

    你确定你的DB结构吗?你不能将
    child
    添加到
    Driver
    中,因为它是
    变量
    value=true
    在你的结构中没有驱动程序的任何子级。你能解释你想做什么吗。?关于你的DB结构尝试
    FirebaseDatabase.getInstance().getReference().child(“用户”).child(用户id)
    。它应该更新。基本上你可以在Firebase控制台上模拟它,你不能在
    驱动程序上添加
    +
    (或
    +
    符号),但可以在
    用户上尝试此数据库引用当前用户\u db=FirebaseDatabase.getInstance().getReference().child(“用户”).child(用户id);当前_用户_db.child(“驱动程序”).setValue(真);