10

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.

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!

AL.
  • 36,815
  • 10
  • 142
  • 281
Asmahan
  • 139
  • 1
  • 4
  • 10
  • What's a firstlame? – OneCricketeer Apr 09 '17 at 19:17
  • Reason is as stated in error: Found two getters or fields with conflicting case sensitivity for property: cv – Ivan Pronin Apr 09 '17 at 19:23
  • 1
    @IvanPronin: a quick scan of the code shows only one getter and setter for CV. – Frank van Puffelen Apr 09 '17 at 19:25
  • 1
    There's one `cv` field in Teacher class, and another in `signupTacher`, and a call to it in `CV = (EditText) findViewById(R.id.cv);` – Ivan Pronin Apr 09 '17 at 19:26
  • @Asmh94: can you try what happens when you mark the **fields** as private? So `private String firstlame,lastname,useremail,userpassword, CV, spinner, city...`. If that doesn't fix the problem, change the case if the `CV` field to match your getter setter, so: `private String firstlame,lastname,useremail,userpassword, cv...` (with `cv` being lowercase). – Frank van Puffelen Apr 09 '17 at 19:26
  • 1
    @IvanPronin only the one in the `Teacher` class is used when reading from/writing to the Firebase Database. The other one isn't in the way (as far as I can see). – Frank van Puffelen Apr 09 '17 at 19:27
  • Did you read the exception? "Found two getters or fields with conflicting case sensitivity for property: cv" – jediz Apr 09 '17 at 20:21

6 Answers6

11

Try to fix the capitalization on your fields and methods. firstName, getFirstName... etc

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. And the method is then get or setCv

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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
6

Simply make sure that all the variables in your model class are declared as private

ie

private String name;

instead of

String name;
Martin Mbae
  • 1,108
  • 1
  • 16
  • 27
1

I just got the same problem but i solved it first check that you have same variable name as firebase jason table variable. 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 .

Lovnish Jain
  • 332
  • 1
  • 6
0
  1. Brother your all variables in class SignupTeacher is private.
  2. Just make sure the variables you are using in this class should as it is as you are using in firebase. Look in my case

    this is fire base objects

This is my android class

  1. And put the variables in your class in order the order you used in firebase Thanks
Smarpit
  • 99
  • 1
  • 13
Malik Faizan
  • 142
  • 1
  • 4
0

The Firebase JSON serialization name is controlled by the annotation PropertyName, if the name starts with a capital letter. You have two options

1) Complain to complain
2) use @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

Mudassar Ashraf
  • 734
  • 7
  • 8
0

You can map the name without changing variable name using @PropertyName annotation

Kotlin Eg:

enter image description here

data class Category(
    @PropertyName("Image")
    var img:String="",
    @PropertyName("Names")
    var name:String="")
d-feverx
  • 1,424
  • 3
  • 16
  • 31