Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatabaseException: Found two getters or fields with conflicting case sensitivity

Every time I try to retrieve data from my database, I get

com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: n

for any of my fields that are a single letter. Googling this issue gives 0 results and I can find no case incongruities in my code. I don't know if this is a bug in Firebase or if I have to do something special for any fields with names 1 character long.

Here is the rest of the error report if it makes a difference (the line of my code which it references is a simple

params = dataSnapshot.getValue(Parameters.class);

which works everywhere else:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: osu.gd_prototype, PID: 11345
com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: n
at com.google.android.gms.internal.zzaix$zza.zziw(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.<init>(Unknown Source)
at com.google.android.gms.internal.zzaix.zzj(Unknown Source)
at com.google.android.gms.internal.zzaix.zzd(Unknown Source)
at com.google.android.gms.internal.zzaix.zzb(Unknown Source)
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at osu.gd_prototype.DataSend$1.onDataChange(DataSend.java:107)
at com.google.android.gms.internal.zzafp.zza(Unknown Source)
at com.google.android.gms.internal.zzagp.zzSu(Unknown Source)
at com.google.android.gms.internal.zzags$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

Here is the code for parameters with the relevant offending getters and setters of the fields which throw the error:

public class Parameters {

    public int K;
    public double L;
    public int D;
    public int N;

    public Parameters() {

}

    public double getL(){
        return L;
    }
    public void setL(double lVal){
        L = lVal;
    }

    public int getK(){
        return K;
    }
    public void setK(int kVal){
        K = kVal;
    }

    public int getD(){
        return D;
    }
    public void setD(int dVal){
        D = dVal;
    }

    public int getN(){
        return N;
    }
    public void setN(int nVal){
        N = nVal;
    }
}
like image 883
user6462035 Avatar asked Jun 14 '16 00:06

user6462035


3 Answers

The Firebase Database consider these items when serializing/deserializing JSON:

  • public fields
  • JavaBean-like property getters/setters

Since you have both a public field N and getN()/setN() methods, it considers the two in conflict. While in this case setting N and calling setN() leads to the same result, that may not always be the case. The chance of getting it wrong is too big, which is why the scenario is simply not allowed.

The error message is a bit of a red herring in this case. We should improve that.

like image 135
Frank van Puffelen Avatar answered Nov 14 '22 02:11

Frank van Puffelen


Convert the following fields from public to private

public int K;
public double L;
public int D;
public int N;

to

private int K;
private double L;
private int D;
private int N;
like image 20
oliro Amuri bonface Avatar answered Nov 14 '22 04:11

oliro Amuri bonface


I found a different solution to keep my field public String id and at the same time have the method public String getId() which I needed to implement because of an interface: Simply mark the method with @Exclude, e.g.:

public class Group implements Identifiable<String>
{
    public String id;

    protected Group ()
    {
    }

    public Group ( String id )
    {
        this.id = id;
    }

    @Exclude
    @Override
    public String getId ()
    {
        return id;
    }
}
like image 23
Stephan Henningsen Avatar answered Nov 14 '22 03:11

Stephan Henningsen