问题描述
我正在使用Google的Android版firebase-database SDK v9.0.1。我有我的应用程序挂钩到Firebase,并可以读取和写入数据在不同的位置。
然而,我不能得到一个特定的布尔字段绑定使用 / code>,那么getter必须被命名为 isIsUp()或 getIsUp()。或者,如果您想要一个名为 isUp 的getter,那么字段名称将是 up 。
I'm using Google's firebase-database SDK for Android, v9.0.1. I have my app hooked up to Firebase and can read and write data at various locations.
However, I cannot get a specific boolean field to bind using dataSnapshot.getValue(PingReport.class) and I keep getting an error in my logs that says No setter/field for isUp found on class com.myapp.PingReport when the field clearly exists in my model.
Here's the JSON in the Firebase database:
{ "durationMs": 364, "isUp": true, "timestampMillis": 1464916019971 }
and here's the model class:
public class PingReport { private long durationMs; private boolean isUp; private long timestampMillis; public PingReport() { // required by Firebase } public PingReport(long durationMs, boolean isUp, long timestampMillis) { this.durationMs = durationMs; this.isUp = isUp; this.timestampMillis = timestampMillis; } public long getDurationMs() { return durationMs; } public boolean isUp() { return isUp; } public long getTimestampMillis() { return timestampMillis; } }
If I call getDurationMs() or getTimestampMillis() the correct values are returned, but the value returned from isUp() is always false. I have tried different combinations of naming it up and isUp and mUp and adding setters setUp(boolean up) and setIsUp(boolean isUp), but nothing seems to work. The documentation for the Android SDK not very detailed. Is there some trick or detail I'm overlooking?
If your boolean field is named isUp, then the getter must be named isIsUp() or getIsUp(). Alternatively, if you want a getter named isUp, the field name would be up.
这篇关于Firebase不会将布尔值绑定到字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!