我目前正在将Firebase UI组件转换为Firestore UI组件。构建FirestoreRecyclerAdapter
并手动调用adapter.startListening()
或通过new FirestoreRecyclerOptions.Builder().setLifeCycleOwner()
初始化时,我偶然发现了以下致命异常。
FATAL EXCEPTION: main
Process: packagename, PID: 3129
java.lang.NoSuchMethodError: No virtual method getDocument()Lcom/google/firebase/firestore/DocumentSnapshot; in class Lcom/google/firebase/firestore/DocumentChange; or its super classes (declaration of 'com.google.firebase.firestore.DocumentChange' appears in /data/app/packagename-yHh4aIRPAZwxxRYgunJivQ==/split_lib_dependencies_apk.apk)
at com.firebase.ui.firestore.FirestoreArray.onDocumentAdded(FirestoreArray.java:98)
at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:83)
at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:21)
at com.google.firebase.firestore.zzi.onEvent(Unknown Source:17)
at com.google.android.gms.internal.zzeyn.zza(Unknown Source:6)
at com.google.android.gms.internal.zzeyo.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
错误表明类DocumentSnapshot
不包含检查后正确的方法getDocument
。然而,这也是FirebaseUI在其文档中说明此实现的方式,我无法弄清楚我在哪里做错了。
用于回收商的查询
Query query = mFirestore.collection("spots");
,该集合已存在且内有documents
。
带查询的适配器
mRecyclerView = (RecyclerView) view;
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
Query query = mFirestore.collection("spots");
FirestoreRecyclerOptions<SpotModel> options = new FirestoreRecyclerOptions.Builder<SpotModel>().setQuery(query, SpotModel.class).setLifecycleOwner(this).build();
mAdapter = new FirestoreRecyclerAdapter<SpotModel, SpotHolder>(options) {
@Override
public SpotHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_spot, parent, false);
return new SpotHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull SpotHolder holder, int position, @NonNull SpotModel model) {
holder.bind(model);
}
};
mRecyclerView.setAdapter(mAdapter);
FirebaseUI依赖项
implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
implementation 'com.firebaseui:firebase-ui-firestore:3.2.2'
正在片段的onCreateView
方法中初始化适配器。我按照FirebaseUI的Github页面上的说明进行操作但没有成功(link)
答案 0 :(得分:1)
请尽量不要发帖。
对于其他人:这是known issue,将在与Play Services 12.0.1配对的FUI 3.3.0中修复。目前,降级到Play Services 11.8.0可以解决问题。