![](/img/trans.png)
[英]No properties to serialize found on class org.json.JSONObject when calling Firebase with getValue
[英]Firebase Firestore Distributed Counter - No Properties to Serialize Found
我已经阅读并根据这篇文章中的建议更改了我的代码。
但是,我的问题仍然存在,出现相同的错误:
java.lang.RuntimeException: No properties to serialize found on class com.blush.android.blush.chat.chatCloudCommunications.ChatCloudSentMessageToFirestore$Counter
我在一个名为ChatCloudSentMessageToFirestore的公共类中运行下面的所有内容。 我省略了在同一个类中定义的“createCounter”、“getCounter”和“incrementCounter”。 我这样做是为了保持代码简短,因为它们与 Firebase Firestore 网站上定义的相同: https ://firebase.google.com/docs/firestore/solutions/counters 所以不太可能是原因错误(除非他们需要我不知道的任何修改)。
public class Counter {
int numShards;
public Counter(int numShards) {
this.numShards = numShards;
}
}
// counters/${ID}/shards/${NUM}
public static class Shard {
int count;
public Shard(){}
public Shard(int count) {
this.count = count;
}
}
我在同一个类中也有这个参考:
DocumentReference counterChrisDocRef = db.collection("users")
.document("ypiXrobQxuZ0wplN5KO8gJf934")
.collection("conversations")
.document("conversation0") //Specified conversation
.collection("messageCounter")
.document("shards");
我正在尝试使用这种方法中的计数器:
public void addSentMessageToFirestoreDB(final Map<String, Object> messageSent) {
WriteBatch batch = db.batch();
createCounter(counterChrisDocRef, 1);
incrementCounter(counterChrisDocRef, 1);
DocumentReference chrisSentMessageRef = db.collection("users")
.document("ypiXrobQxuZ0wplN5KO8gJf934")
.collection("conversations")
.document("conversation0") //Specified conversation
.collection("messages")
.document("message" + getCount(counterChrisDocRef) + " (sent)");
batch.set(chrisSentMessageRef, messageSent);
batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
因为您根本没有在您的课程中为您的字段使用公共吸气剂,所以请将您的所有字段public
,因为在您的代码中现在是默认的。 为了直接在您的字段上设置值,您的字段必须是public
。 如果你想让你的字段私有,只需添加相应的公共获取器,一切都会正常工作。
还请从您的Shard
类中删除static
关键字。 没有必要使该类成为static
的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.