Java Firebase Firestore分布式计数器-未找到要序列化的属性
我已经阅读并根据本文的建议修改了代码 但是,我的问题仍然存在,出现了相同的错误:Java Firebase Firestore分布式计数器-未找到要序列化的属性,java,android,firebase,google-cloud-firestore,counter,Java,Android,Firebase,Google Cloud Firestore,Counter,我已经阅读并根据本文的建议修改了代码 但是,我的问题仍然存在,出现了相同的错误: java.lang.RuntimeException: No properties to serialize found on class com.blush.android.blush.chat.chatCloudCommunications.ChatCloudSentMessageToFirestore$Counter 我在一个名为ChatCloudSentMessageToFirestore的公共类中运行下
java.lang.RuntimeException: No properties to serialize found on class com.blush.android.blush.chat.chatCloudCommunications.ChatCloudSentMessageToFirestore$Counter
我在一个名为ChatCloudSentMessageToFirestore的公共类中运行下面的所有内容。我省略了在同一个类中定义的“createCounter”、“getCounter”和“incrementCounter”。我这样做是为了保持代码简短,因为它们与Firebase Firestore网站上定义的内容相同:因此不太可能是错误的原因(除非它们需要我不知道的任何修改)
我在同一类中也有此引用:
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 void addSentMessageToFirestoreDB(最终映射消息已发送){
WriteBatch batch=db.batch();
createCounter(counterChrisDocRef,1);
递增计数器(计数器chrisdocref,1);
DocumentReference chrisSentMessageRef=db.collection(“用户”)
.文件(“ypiXrobQxuZ0wplN5KO8gJf934”)
.收集(“对话”)
.document(“conversation0”)//指定的对话
.收集(“信息”)
.document(“message”+getCount(counterChrisDocRef)+(sent)”;
batch.set(chrissentmesseref,messageSent);
batch.commit().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
}
});
由于您的类中的字段根本没有使用公共getter,请将所有字段设置为公共的,因为在您的代码中现在是默认的。为了直接在字段上设置值,您的字段必须是公共的
。如果您想让字段私有,只需将相应的公共getter添加到一切都会好起来的
还请从您的Shard
类中删除static
关键字。无需使该类static
,因为您的类中的字段根本没有使用公共getter,请使所有字段公共
,因为在您的代码中现在是默认值。为了直接设置值在您的字段上,您的字段必须是公共的
。如果您想让您的字段成为私有的,只需添加相应的公共getter,一切都会正常工作
还请从Shard
类中删除static
关键字。无需将该类设置为static
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) {
}
});