【发布时间】:2018-08-27 11:11:09
【问题描述】:
我已经根据post 中的建议阅读并更改了我的代码。
但是,我的问题仍然存在,得到同样的错误:
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) {
}
});
【问题讨论】:
标签: java android firebase google-cloud-firestore counter