英文:
Adding Firestore document doesn't Fail or Succeed
问题
以下是您提供的代码的翻译部分:
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或Point 2。我对Android和Java都不太了解,所以我不确定Logcat中的内容的含义:
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: 访问隐藏字段Ljava/nio/Buffer;->address:J(淡灰色名单,反射)
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: 没有活动的令牌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}] 无法解析名称。 状态={1}
2020-09-05 09:54:36.271 19216-19216/com.example.app W/ActivityThread: handleWindowVisibility: 没有活动的令牌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}] 无法解析名称。 状态={1}
2020-09-05 09:54:42.040 19216-19216/com.example.app I/AssistStructure: 扁平化的最终辅助数据:3832字节,包含1个窗口,12个视图
2020-09-05 09:54:43.993 19216-19216/com.example.app I/AssistStructure: 扁平化的最终辅助数据:3832字节,包含1个窗口,12个视图
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)
它之前是正常运行的,但突然间停止工作了,所以我不确定我做了什么。如果您需要更多的代码,我也可以提供。提前谢谢您!
英文:
I am trying to add documents to Firebase Firestore from my android app. This is the code that I currently have.
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
When I run this code it will reach Point 1 and Point 4, but never Point 3 or Point 2. I'm pretty new to android and java so I'm not sure what the things in the Logcat mean either:
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)
It was functioning, but suddenly it stopped working, so I'm not sure what I did. If you need any more code, I can provide it as well. Thank you in advance!
答案1
得分: 0
你可能需要清除当前正在使用的 AVD 的数据,然后尝试再次运行。
我认为 AVD 的互联网连接可能没有正常工作,或者同时运行的内容过多,因此当我清除了数据后,问题得以解决。我不认为在真实设备上会出现这种情况,但我不太确定。希望这对其他遇到这个问题的人有用。
英文:
You probably need to Wipe Data from the current AVD you are using and try running it agian.
I think that the AVD Internet wasn't working correctly, or too much was running on it so when I wiped the data this was solved. I don't think that this can happen on a real device, but I'm not sure. Hopefully this is works for anyone else with this issue.
答案2
得分: 0
我曾经遇到过相同的问题,对我来说是模拟器出了问题。我将它降级至 v31.2.10,降级后尝试的所有插入操作在 Firestore 中都成功完成了。
在此处阅读更多信息:Firebase 不在 Android Studio 模拟器上运行!
您可以从 https://developer.android.com/studio/emulator_archive 获取较旧的模拟器版本。
英文:
I had the same problem and for me it was the emulator. I've downgraded it to v31.2.10 and all the attempts when the inserts didn't work to the Firestore completed after the downgrade.
Read more here: Firebase doesn't work on Android Studio Emulator!
You can get older emulator versions from https://developer.android.com/studio/emulator_archive
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论