我正在尝试使用Firestore
。我需要获取所有图像URL,这些URL存储在Firestore
的文件夹中。我目前正在关注This。
使用时:
db.collection("images")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
我在下面收到错误消息。
最初我是
程序类型已经存在:com.google.common.annotations.GwtCompatible
该问题通过以下方式解决:
implementation ("com.google.firebase:firebase-firestore:17.0.3"){
exclude group: 'com.google.guava'
}
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
at com.google.firebase.Timestamp.zza(SourceFile:136)
at com.google.firebase.Timestamp.<init>(SourceFile:47)
at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
at java.lang.Thread.run(Thread.java:764)
07-26 09:56:29.396 25793-25793/com.apps.dp E/UncaughtException:
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
at com.google.firebase.Timestamp.zza(SourceFile:136)
at com.google.firebase.Timestamp.<init>(SourceFile:47)
at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
at java.lang.Thread.run(Thread.java:764)
最近6个小时,我一直在为此苦苦挣扎。我能在这方面得到一些帮助吗?我还有一个问题,是否有可能使用android中的Firestore
APi从文件夹获取所有图像url。还是我先将这些URls保存在Firebase数据库中?已经在此Like this one上签出了一些帖子,表明不可能。
答案 0 :(得分:3)
根据您的最新评论,请注意,为了检索Cloud Storage for Firebase中托管的文件夹中的所有文档,您需要了解path
或download URL
。无法不知道就从文件夹中简单地获取所有文件。
为解决此问题,我建议在上传任何文件后,将download URL
存储到Firebase Real-time Database或新的Cloud Firestore之类的数据库中。请在下面查看获取download URL
的简单示例。
storageRef.child("YourFolderName").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for "YourFolderName/YourFile.pdf"
// Add it to your database
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
最后,只需查询Firebase实时数据库中的url
节点或Cloud Firestore中的url
集合,并在需要时使用它们即可。