在以下说明的情况下,我遇到了问题类型DocumentReference
的问题:
这是我的代码:
DocumentReference calRef = db.document(mPath);
calRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot calSnapshot,
@Nullable FirebaseFirestoreException e) {
if (calSnapshot != null && calSnapshot.exists()) {
Log.d(TAG,calSnapshot.toString());
DocumentReference dataRef=calSnapshot.getDocumentReference("breviario/oficio");
if (e != null || dataRef==null) {
//launchVolley();
return;
}
dataRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot dataSnapshot) {
mBreviario = dataSnapshot.toObject(Breviario.class);
showData();
}
});
} else {
//launchVolley();
}
}
});
我遇到的错误是:
2019-12-04 16:36:59.927 5355-5355/org.my.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.my.app, PID: 5355
java.lang.IllegalArgumentException: Invalid field path (breviario/oficio). Paths must not contain '~', '*', '/', '[', or ']'
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:141)
对象calSnapshot
具有数据,我可以在日志中看到它:
DocumentSnapshot{
key=esp/v2019_2/calendar/2019/12/04,
metadata=SnapshotMetadata
{hasPendingWrites=false, isFromCache=true},
doc=Document
{
key=esp/v2019_2/calendar/2019/12/04,
data=ArraySortedMap{
(breviario=>ArraySortedMap{(mixto=>liturgia/lh/0/01080104), (oficio=>liturgia/lh/1/01080104)};),
(metaLiturgia=>ArraySortedMap{(fecha=>20191204), (mensaje=>), (salterio=>), (semana=>Semana XXXIV), (tiempo=>07)};)};,
version=SnapshotVersion(seconds=1575473373, nanos=705628000), documentState=SYNCED}
}
我不知道如何定位DocumentReference
中的oficio
。
答案 0 :(得分:1)
错误消息告诉您/
是该字段的无效字符。 Firestore中的嵌套字段用.
而不是/
分隔。改用它:
calSnapshot.getDocumentReference("breviario.oficio");