简体   繁体   English

发现两个 getter 或字段的属性区分大小写冲突

[英]Found two getters or fields with conflicting case sensitivity for property

Can anyone check if there are errors in it because I always get an error任何人都可以检查它是否有错误,因为我总是收到错误

com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property. com.google.firebase.database.DatabaseException:发现两个 getter 或字段的属性区分大小写冲突。

this is my code signupTeacherActivity:这是我的代码注册教师活动:

public class signupTeacher extends AppCompatActivity {
EditText userfirstname,userlastname, useremail,userpassword,userconfirmpassword, CV,city;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
Spinner spinner;
String defaultuserprofileimg;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup_teacher);
    getSupportActionBar().setTitle("Sign Up");
    findViewByIds();

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.subject_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}

public void signUpUser(View view) {
    if(useremail.getText().toString().length()==0 || userpassword.getText().toString().length()==0||userfirstname.getText().length()==0 ||userconfirmpassword.getText().length()==0 ||userlastname.getText().length()==0){
        Toast.makeText(signupTeacher.this, "Please enter all the fields to proceed further.",
                Toast.LENGTH_SHORT).show();
    }else {
        if(spinner.getSelectedItem().toString().equals("Select a Subject")){
            Toast.makeText(signupTeacher.this, "Please select a valid Subject.", Toast.LENGTH_LONG).show();
        }
        else {
            mAuth = FirebaseAuth.getInstance();
            mAuth.createUserWithEmailAndPassword(useremail.getText().toString(), userpassword.getText().toString())
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Log.d("demo", "createUserWithEmail:onComplete:" + task.isSuccessful());

                            if (!task.isSuccessful()) {
                                Toast.makeText(signupTeacher.this, task.getException().toString(),
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                mDatabase = FirebaseDatabase.getInstance().getReference();
                                Teacher user = new Teacher(userfirstname.getText().toString(), userlastname.getText().toString(), useremail.getText().toString(), userpassword.getText().toString() , CV.getText().toString(), spinner.getSelectedItem().toString(), city.getText().toString(),task.getResult().getUser().getUid().toString(), defaultuserprofileimg);
                                mDatabase.child("Teachers").child(task.getResult().getUser().getUid().toString()).setValue(user);
                                Intent i = new Intent(signupTeacher.this, MainActivity.class);
                                startActivity(i);
                                Toast.makeText(signupTeacher.this, "Succesfully registered. Please login with the created credentials",
                                        Toast.LENGTH_LONG).show();
                                mAuth = FirebaseAuth.getInstance();
                                mAuth.signOut();
                                finish();
                            }

                        }

                    });
        }
    }

}

public void goToLogin(View view) {
    Intent i=new Intent(signupTeacher.this,MainActivity.class);
    startActivity(i);
    finish();

}
private void findViewByIds() {
    userfirstname= (EditText)findViewById(R.id.firstname);
    userlastname= (EditText) findViewById(R.id.lastname);
    userpassword= (EditText) findViewById(R.id.password);
    userconfirmpassword= (EditText)findViewById(R.id.confirmpassword);
    useremail= (EditText) findViewById(R.id.email);
    spinner = (Spinner) findViewById(R.id.spSubject);
    CV = (EditText) findViewById(R.id.cv);
    city = (EditText) findViewById(R.id.City);

}}

My class Teacher:我的班主任:

public class Teacher  implements Serializable {
String firstlame,lastname,useremail,userpassword, CV, spinner, city, userkey,userimageuri;

public String getFirstlame() {
    return firstlame;
}

public void setFirstlame(String firstlame) {
    this.firstlame = firstlame;
}

public String getLastname() {
    return lastname;
}

public void setLastname(String lastname) {
    this.lastname = lastname;
}

public String getUseremail() {
    return useremail;
}

public void setUseremail(String useremail) {
    this.useremail = useremail;
}

public String getUserpassword() {
    return userpassword;
}

public void setUserpassword(String userpassword) {
    this.userpassword = userpassword;
}

public String getCv() {
    return CV;
}

public void setCv(String CV) {
    this.CV = CV;
}

public String getSpinner() {
    return spinner;
}

public void setSpinner(String spinner) {
    this.spinner = spinner;
}
public String getCity() {return city; }

public void setCity(String city) {
    this.city = city;
}

public String getUserkey() {
    return userkey;
}

public void setUserkey(String userkey) {
    this.userkey = userkey;
}

public String getUserimageuri() {
    return userimageuri;
}

public void setUserimageuri(String userimageuri) {
    this.userimageuri = userimageuri;
}


public Teacher(String firstlame, String lastname, String useremail,   String userpassword, String CV,  String spSubject ,  String City, String userkey, String userimageuri  ) {

    this.firstlame = firstlame;
    this.lastname = lastname;
    this.useremail = useremail;
    this.userpassword = userpassword;
    this.CV = CV;
    this.spinner = spSubject;
    this.city = City;
    this.userkey=userkey;
    this.userimageuri=userimageuri;

}

public Teacher(){

}}

logcat:日志猫:

04-09 21:41:30.570 12739-12739/com..example.*.*hers E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.example.faay.hireteachers, PID: 12739
                                                                           com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: cv
                                                                               at com.google.android.gms.internal.zzbqi$zza.zzjs(Unknown Source)
                                                                               at com.google.android.gms.internal.zzbqi$zza.<init>(Unknown Source)
                                                                               at com.google.android.gms.internal.zzbqi.zzi(Unknown Source)
                                                                               at com.google.android.gms.internal.zzbqi.zzax(Unknown Source)
                                                                               at com.google.android.gms.internal.zzbqi.zzaw(Unknown Source)
                                                                               at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
                                                                               at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
                                                                               at com.example.faay.hireteachers.signupTeacher$1.onComplete(signupTeacher.java:63)
                                                                               at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
                                                                               at android.os.Handler.handleCallback(Handler.java:739)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                               at android.os.Looper.loop(Looper.java:158)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)

Thanks for any sort of help!感谢您的任何帮助!

Try to fix the capitalization on your fields and methods.尝试修复您的字段和方法的大小写。 firstName , getFirstName ... etc firstName , getFirstName ... 等

Your error is on the CV field, where the method should be setCV to match the case of the field, though, you should name it cv following Java naming contentions.您的错误出现在CV字段上,该方法应该设置为setCV以匹配该字段的大小写,但是,您应该在 Java 命名争用之后将其命名为cv And the method is then get or setCv然后方法是getsetCv

public String getCv() {
    return cv;
}

public void setCv(String cv) {
    this.cv = cv;
 }

I would also suggest not storing passwords as part of your objects.我还建议不要将密码存储为对象的一部分。 Especially if they are plain text.特别是如果它们是纯文本。 You send passwords to the database to check for validity or to update;您将密码发送到数据库以检查有效性或更新; it's seldom a good idea to read them out and persist them elsewhere将它们读出来并保留在其他地方很少是一个好主意

Simply make sure that all the variables in your model class are declared as private只需确保模型类中的所有变量都声明为私有

ie IE

private String name;

instead of代替

String name;
  1. Brother your all variables in class SignupTeacher is private.兄弟,您在类SignupTeacher所有变量都是私有的。
  2. Just make sure the variables you are using in this class should as it is as you are using in firebase.只需确保您在此类中使用的变量应该与您在 firebase 中使用的一样。 Look in my case看看我的情况

    这是火基对象

这是我的安卓课

  1. And put the variables in your class in order the order you used in firebase Thanks并按照您在 firebase 中使用的顺序将变量放在您的班级中 谢谢

I just got the same problem but i solved it first check that you have same variable name as firebase jason table variable.我刚刚遇到了同样的问题,但我解决了它首先检查您是否具有与 firebase jason 表变量相同的变量名。 In your case CV is returned as Cv in your java class so correct it first than your check the firebase jason table name of that variable CV .在您的情况下, CV 在您的 java 类中作为 Cv 返回,因此首先更正它,而不是检查该变量 CV 的 firebase jason 表名称。

The Firebase JSON serialization name is controlled by the annotation PropertyName, if the name starts with a capital letter. Firebase JSON 序列化名称由注释 PropertyName 控制(如果名称以大写字母开头)。 You have two options你有两个选择

1) Complain to complain 1)投诉投诉
2) use @PropertyName("Complain") 2) 使用@PropertyName("Complain")

public class Order implements Serializable {

private String Complain;

public Order() {
 Complain = "";
}

@PropertyName("Complain")
public String getComplain() {
    return Complain;
}

@PropertyName("Complain")
public void setComplain(String complain) {
    Complain = complain;
}

} }

reference https://stackoverflow.com/a/45809982/9315431参考https://stackoverflow.com/a/45809982/9315431

You can map the name without changing variable name using @PropertyName annotation您可以使用@PropertyName注释在不更改变量名称的情况下映射名称

Kotlin Eg:科特林 例如:

在此处输入图片说明

data class Category(
    @PropertyName("Image")
    var img:String="",
    @PropertyName("Names")
    var name:String="")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发现两个 getter 或属性的区分大小写冲突的字段:状态 - Found two getters or fields with conflicting case sensitivity for property: status 发现两个吸气剂或字段的属性区分大小写冲突:image - Found two getters or fields with conflicting case sensitivity for property: image com.google.firebase.database.DatabaseException:找到两个具有属性区分大小写的getter或字段 - com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: name 发现两个 getter 或属性的区分大小写冲突的字段: s 但是,我没有类的“s”属性,也没有 Firebase - Found two getters or fields with conflicting case sensitivity for property: s however, I don't have an "s" property of the classes nor Firebase 构建为发行版APK后出现错误,但调试APK则没有错误-错误:发现两个吸气剂或区分大小写的字段 - Error after building as release APK but no error with debug APK - Error: Found two getters or fields with conflicting case sensitivity R8 混淆导致 @PropertyName 无法工作导致 DatabaseException:找到两个有冲突的 getter 或字段 - R8 obfuscation results in @PropertyName not working causing DatabaseException: Found two getters or fields with conflicting 发现名称冲突的吸气剂 - Found conflicting getters for name 发现名称冲突的吸气剂:isImportantForAccessibility - Found conflicting getters for name: isImportantForAccessibility 找到名称冲突的吸气剂:isFocusable - Found conflicting getters for name: isFocusable 发现名称的冲突吸气剂:getText - found conflicting getters for name: getText
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM