我遇到了一个问题 addOnCompleteListener()
需要使用的函数,以便将数据从CloudFireStore检索到我的android应用程序(在android studio中开发)。
这是我使用的一个简单代码:
FirebaseFirestore mDatabase;
mDatabase = FirebaseFirestore.getInstance();
mDatabase.collection("SavedGames")
.document("game1")
.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Log.d(TAG, "DocumentSnapshot data: " + document.getData());
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
});
我从firebase官方网站上获取了这个代码。调试时,每次 get().addOnCompleteListener(...)
,光标全部退出。我尝试卸载我的应用程序,更改我的授权规则,检查我是否有google-service.json,清理我的android项目,更新gradles,但没有解决这个问题。
这是我的身材。grad尔:
implementation 'androidx.browser:browser:1.3.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-auth:20.0.1'
implementation 'com.google.firebase:firebase-firestore:22.0.1'
implementation 'com.google.firebase:firebase-database:19.6.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
有什么能引起这种情况的建议吗?
暂无答案!
目前还没有任何答案,快来回答吧!