DatabaseException: 发现两个 getter 或字段区分大小写冲突 [英] DatabaseException: Found two getters or fields with conflicting case sensitivity

查看:23
本文介绍了DatabaseException: 发现两个 getter 或字段区分大小写冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试从我的数据库中检索数据时,我都会得到

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

对于我的任何单个字母的字段.谷歌搜索这个问题给出了 0 个结果,我在我的代码中没有发现不协调的情况.我不知道这是否是 Firebase 中的错误,或者我是否必须对名称长度为 1 个字符的任何字段执行一些特殊操作.

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);

适用于其他任何地方:

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)

以下是参数的代码,其中包含引发错误的字段的相关违规 getter 和 setter:

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;
    }
}

推荐答案

Firebase 数据库在序列化/反序列化 JSON 时考虑这些项目:

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

  • 公共字段
  • 类似 JavaBean 的属性 getter/setter

由于您同时拥有公共字段 NgetN()/setN() 方法,因此它认为两者存在冲突.虽然在这种情况下设置 N 和调用 setN() 会导致相同的结果,但情况并非总是如此.出错的几率太大了,这就是为什么这个场景是根本不允许的.

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.

这篇关于DatabaseException: 发现两个 getter 或字段区分大小写冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆