我尝试用文本框中的值设置文档路径。
但是,每当我尝试执行此应用程序时,它都会继续崩溃。
DocumentReference docRef = db.collection("Users").document(textDisplay2.getText().toString());
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null && document.exists()) {
Log.d("TAG", document.getString("name")); //Print the name
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
最佳答案
DocumentReference docRef = db.collection("Users").document(String.valueOf(textDisplay2.getText());
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null && document.exists()) {
Log.d("TAG", document.getString("name")); //Print the name
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
关于android - 如何用文本框中的值替换文档路径?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54588423/