FirebaseFirestore 插入
2018-03-20
196
328617136
它没有插入DB,也没有给任何错误。我不明白错误在哪里!我不知道什么问题 主页。如果是逻辑错误,请告诉我! 一些帮助将不胜感激!预先感谢!
1个回答
问题是因为您在检查标题和说明是否为空时错误地访问了变量,如下所示:
if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(description_val)) {
应该是:
public void createPost() {
String title_val = title.getText().toString().trim();
String post_description_val = description.getText().toString().trim();
String user_id=mAuth.getCurrentUser().getUid();
if (!title_val.isEmpty() && !post_description_val.isEmpty()) {
progressBar.setVisibility(View.VISIBLE);
Map<String, String> posts = new HashMap<>();
posts.put("description",description_val);
posts.put("title", title);
posts.put("user_id", user_id);
progressBar.setVisibility(View.GONE);
db.collection("posts")
.add(posts)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText( Post.this,"Success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w( TAG,"Error adding document", e);
}
});
}
}
编辑:
Levi Moreira
2018-03-20