java - 不会在 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());
}
解决方案
您必须像其他实体一样在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。
推荐阅读
- c# - 在一个应用程序中合并两个 Asp.Net Core API
- javascript - 没有流程的 React Native?
- dependency-injection - 在 NestJS 中,如何将动态模块异步选项注入模块内部导入?
- sql - 重构 Oracle 存储过程以使用 BULK COLLECT
- masstransit - MassTransit 端点名称在 ConsumerDefinition 中被忽略
- python - selenium.common.exceptions.WebDriverException:消息:即使更新后也无法访问 chrome
- angular - 在后端渲染 ApexCharts PNG 文件?
- mongodb - MongoDB 在 Kubernetes 中不持久
- geometry - 立体校准后使用外部参数的左图像到右图像变形(2d-2d)
- python - 输入变量框没有出现并要求输入值并且循环不起作用