gpt4 book ai didi

android - Firestore 操作(add()、set())不起作用

转载 作者:行者123 更新时间:2023-12-03 15:50:16 37 4
gpt4 key购买 nike

我正在尝试将用户详细信息添加到 Firestore 数据库 ,但不能在其中写入数据。

实际上没有一个监听器被触发 onSuccess()也不是 onFailure() .

这是我的代码。

Map<String,Object> userlol = new HashMap<>();
userlol.put("name",name);
userlol.put("email",email);
userlol.put("uid",currentUser.getUid());
Log.d(TAG, "we are here");
CollectionReference dc = db.collection("users");
DocumentReference dd = dc.document(currentUser.getUid());
dd.set(userlol)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(SignupActivity.this, "User Added" ,
Toast.LENGTH_SHORT).show();
Log.d(TAG,"User added to database");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(SignupActivity.this, "ERROR" +e.toString(),
Toast.LENGTH_SHORT).show();
Log.d(TAG, e.toString());
}
});

我的 logcat 中没有 toast 也没有日志。我可以看到

D/logging: we are here



此日志和此方法后的日志。

规则没有问题,因为 onFailure() 也不起作用。

我已经搜索了所有可能的东西,但没有任何效果。

最佳答案

我无法触发任何回调的唯一方法是当我的设备上没有网络连接时。在这种情况下,这种行为是有意义的,因为只有在服务器上提交(或拒绝)数据时才认为任务已完成。

要轻松查看 Firestore 客户端是否确实无法连接到服务器,请启用调试日志记录:

FirebaseFirestore.setLoggingEnabled(true);

这样做后我看到这样的日志条目:

11-12 07:56:21.366 10034-10066/com.firebase.firestorestackoverflow I/Firestore: (0.6.6-dev) [zzetk]: (b6322ac) Stream closed with status: zzcd{code=UNAVAILABLE, description=null, cause=java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname at java.net.InetAddress.lookupHostByName(InetAddress.java:470) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at io.grpc.internal.zzbj$zzb.zztu(Unknown Source) at io.grpc.internal.zzbk.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname) at libcore.io.Posix.android_getaddrinfo(Native Method) at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55) at java.net.InetAddress.lookupHostByName(InetAddress.java:451) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)  at java.net.InetAddress.getAllByName(InetAddress.java:215)  at io.grpc.internal.zzbj$zzb.zztu(Unknown Source)  at io.grpc.internal.zzbk.run(Unknown Source)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)  at java.lang.Thread.run(Thread.java:818)  }.

关于android - Firestore 操作(add()、set())不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47249309/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com