添加Firestore文档不会失败或成功

时间:2020-09-05 15:02:20

标签: java android firebase google-cloud-firestore

我正在尝试从我的Android应用程序向Firebase Firestore添加文档。这是我目前拥有的代码。

FirebaseFirestore db = FirebaseFirestore.getInstance();


Map<String, Object> newuser = new HashMap<>();
        newuser.put("Username",username);
        newuser.put("Password",password);
        newuser.put("Nickname",userNickname);
        newuser.put("Code", "ffff");
        newuser.put( "Othercode", "ffffffff");
        newuser.put("Age", "0");
        
        //Point 1

        db.collection("Users").document(username).set(newuser)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        //Point 2
                    }
                })

                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        //Point 3
                    }
                });
//Point 4

当我运行此代码时,它将到达Point 1和Point 4,但永远不会到达Point 3或Point2。我是android和java的新手,所以我不确定Logcat中的含义是什么:< / p>

2020-09-05 09:53:53.514 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:53:55.391 19216-19242/com.example.app W/e.librarysearc: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
2020-09-05 09:54:27.236 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:27.260 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:33.134 19216-19216/com.example.app W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@12d6200
2020-09-05 09:54:33.417 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:35.895 19216-19328/com.example.app W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}
2020-09-05 09:54:36.271 19216-19216/com.example.app W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@549ad31
2020-09-05 09:54:36.572 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:36.814 19216-19328/com.example.app W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}
2020-09-05 09:54:42.040 19216-19216/com.example.app I/AssistStructure: Flattened final assist data: 3832 bytes, containing 1 windows, 12 views
2020-09-05 09:54:43.993 19216-19216/com.example.app I/AssistStructure: Flattened final assist data: 3832 bytes, containing 1 windows, 12 views
2020-09-05 09:54:45.386 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:45.408 19216-19245/com.example.app I/chatty: uid=10091(com.example.librarysearch) RenderThread identical 1 line
2020-09-05 09:54:45.437 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:51.060 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:51.079 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)

它正在运行,但是突然停止工作,所以我不确定我做了什么。如果您需要更多代码,我也可以提供。预先谢谢你!

1 个答案:

答案 0 :(得分:0)

您可能需要从正在使用的当前AVD中清除数据,然后尝试运行它。

我认为AVD互联网工作不正常,或者正在运行太多,因此当我擦除数据时,此问题得以解决。我不认为这会在真实设备上发生,但我不确定。希望这对遇到此问题的任何人都适用。