作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试将用户输入的信息保存到 Firebase,但我的应用程序已停止并崩溃。我创建了一个类,它将采用我声明的变量的 Getter 方法,我试图更改如何保存值(value),但没有任何东西被证明是有效的。MainActivity.java
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DoctorReg();
}
});
}
private void DoctorReg()
{
String name=text.getText().toString().trim();
String lname=text1.getText().toString().trim();
String sex=s.getSelectedItem().toString();
String username=text2.getText().toString().trim();
String password=text3.getText().toString().trim();
String email=text4.getText().toString().trim();
String pnum=text5.getText().toString().trim();
String padd=text6.getText().toString().trim();
String province=s1.getSelectedItem().toString();
String speciality=s2.getSelectedItem().toString();
if(!TextUtils.isEmpty(name))
{
String id=databaseReference.push().getKey();
DoctorReg doctorReg= new DoctorReg(id,name,lname,sex,username,password,email,pnum,padd,province,speciality);
databaseReference.child(id).setValue(doctorReg);
Toast.makeText(this, "Patient is Added ",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this, "You should Enter a Name ",Toast.LENGTH_LONG).show();
}
}
DocRegistration.java
public final class DoctorReg {
String Doctor_Id,F_Name,L_Name,Sex,Username_Doc,Password_Doc,Email_Doc,PNum_Doc,Postal_Address_Doc,Province_Doc,Speciality;
public DoctorReg(){}
public DoctorReg(String doctor_Id, String f_Name, String l_Name, String sex, String username_Doc, String password_Doc, String email_Doc, String PNum_Doc, String postal_Address_Doc, String province_Doc, String speciality) {
this.Doctor_Id = doctor_Id;
this.F_Name = f_Name;
this.L_Name = l_Name;
this.Sex = sex;
this.Username_Doc = username_Doc;
this.Password_Doc = password_Doc;
Email_Doc = email_Doc;
this.PNum_Doc = PNum_Doc;
this.Postal_Address_Doc = postal_Address_Doc;
this.Province_Doc = province_Doc;
this.Speciality = speciality;
}
public String getDoctor_Id() {
return Doctor_Id;
}
public String getF_Name() {
return F_Name;
}
public String getL_Name() {
return L_Name;
}
public String getSex() {
return Sex;
}
public String getUsername_Doc() {
return Username_Doc;
}
public String getPassword_Doc() {
return Password_Doc;
}
public String getEmail_Doc() {
return Email_Doc;
}
public String getPNum_Doc() {
return PNum_Doc;
}
public String getPostal_Address_Doc() {
return Postal_Address_Doc;
}
public String getProvince_Doc() {
return Province_Doc;
}
public String getSpeciality() {
return Speciality;
}
LogCat
04-13 22:27:26.356 7323-7323/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.remy_stolz.myapplication, PID: 7323
com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: doctor_id
at com.google.android.gms.internal.zh.zzhe(Unknown Source)
at com.google.android.gms.internal.zh.<init>(Unknown Source)
at com.google.android.gms.internal.zg.zzf(Unknown Source)
at com.google.android.gms.internal.zg.zzao(Unknown Source)
at com.google.android.gms.internal.zg.zzan(Unknown Source)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
at com.example.remy_stolz.myapplication.DocRegistrationActivity.DoctorReg(DocRegistrationActivity.java:120)
at com.example.remy_stolz.myapplication.DocRegistrationActivity$5.onClick(DocRegistrationActivity.java:99)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-13 22:27:26
最佳答案
遵循 java 的正确命名约定,这将通过解决冲突来帮助您解决这个问题,并且还将避免一些其他错误。此外
UpperCamelCase。
lowerCamelCase
org.acme.project.subsystem
ALL_CAPS。
关于android - 如何将数据字段保存到 Firebase 用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827147/
我是一名优秀的程序员,十分优秀!