首页 > 解决方案 > 不会在 android studio 的 firebase 中保存自定义 java 对象

问题描述

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());
            }

标签: javaandroidfirebase-realtime-databasefirebase-authentication

解决方案


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

    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


推荐阅读