DatabaseException:找到两个具有冲突的大小写敏感的获取者或字段 [英] DatabaseException: Found two getters or fields with conflicting case sensitivity

查看:361
本文介绍了DatabaseException:找到两个具有冲突的大小写敏感的获取者或字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  com.google.firebase.database.DatabaseException:找到了两个相互矛盾的属性区分大小写的字段:n 

对于任何字段单个字母。用谷歌搜索这个问题给出了0的结果,我可以找到我的代码中没有情况不协调。我不知道这是否是Firebase中的一个错误,或者是否需要为名称为1个字符的字段做一些特殊处理。



以下是其余的错误报告,如果它有所作为(我的代码,它引用的行是一个简单的

pre $ params = dataSnapshot.getValue(参数.class);

可以在其他地方使用:

E / AndroidRuntime:FATAL EXCEPTION:main
过程:osu.gd_prototype,PID:11345
com.google.firebase.database.DatabaseException:找到两个getters或者属性相互冲突的区分大小写的字段:n
,com.google.android.gms.internal.zzaix $ zza.zziw(未知来源)
,com.google.android.gms.internal.zzaix $ zza。< init>(未知来源)
在com.google.android.gms.internal.zzaix.zzj(未知来源)
来自com.google.android.gms.internal.zzaix。 zzd(未知来源)
在com.google.android.gms.internal.zzaix.zzb(未知来源)
在com。 google.android.gms.internal.zzaix.za(未知来源)
,位于com.google.firebase.database.DataSnapshot.getValue(未知来源)
,位于osu.gd_prototype.DataSend $ 1.onDataChange(DataSend .java:107)
在com.google.android.gms.internal.zzafp.zza(未知来源)
在com.google.android.gms.internal.zzagp.zzSu(未知来源)
at com.google.android.gms.internal.zzags $ 1.run(未知源代码)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os。 Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:136)
在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的参数代码引发错误:

  public class Parameters {

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

public参数(){

}

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;


$ / code $ / pre

解决方案

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


  • 公共字段

  • JavaBean类属性getters / setters



既然你有一个公共字段 N getN() / setN()方法,它认为两者有冲突。在这种情况下,设置 N 并调用 setN()会导致相同的结果,但并不总是如此。发生错误的可能性太大,这就是为什么这个情况是不允许的。



在这种情况下,错误信息是一个红鲱鱼。我们应该改进。

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

解决方案

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.

这篇关于DatabaseException:找到两个具有冲突的大小写敏感的获取者或字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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