【问题标题】:doesn't save custom java object in firebase in android studio不会在 android studio 的 firebase 中保存自定义 java 对象
【发布时间】:2019-10-07 20:58:35
【问题描述】:
mFirebaseAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(TeacherLogin.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {

            //getting current user and saving student info

            try {
                FirebaseUser user = mFirebaseAuth.getCurrentUser();
                databaseReference = FirebaseDatabase.getInstance().getReference();
                databaseReference.child(user.getUid()).push().setValue(teacherInfo);
                Toast.makeText(TeacherLogin.this, "succesfully signup", Toast.LENGTH_SHORT).show();
            }catch (Exception e) {
                Log.e("Exception is", e.toString());
            }

【问题讨论】:

  • 没有将孩子添加到数据库树但显示“成功注册” ....请帮助我
  • 向您展示 TeacherInfo 类。您在 logcat 中看到任何异常吗?
  • public class TeacherInfo { private String name,department,phone,password,email; ArrayList 主题; public TeacherInfo(){ } public TeacherInfo(String name, String department, String phone, String email,String password) { this.name = name; this.department = 部门; this.phone = 电话; this.email = 电子邮件; this.password=密码; }
  • logcat 没有异常
  • Log.e("Exception is", e.toString()); 是否在 logcat 中打印某些内容?也请回复@AlexMamo

标签: java android firebase-realtime-database firebase-authentication


【解决方案1】:

您必须像其他实体一样在 TeacherInfo 的 构造函数中添加子 subjects

    public TeacherInfo(String name, String department, String phone, String email, String password, ArrayList<String> subjects) { 
        this.name = name; 
        this.department = department; 
        this.phone = phone; 
        this.email = email; 
        this.password = password; 
        this.subjects = subjects;
    }

或者您必须为子实体实现 Geter:Seter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-24
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 2017-05-17
    • 2016-08-04
    相关资源
    最近更新 更多