Я пытаюсь обновить два поля в документе пожарного депо, но ошибка показала, я не уверен, почему ошибка указала, что документ не найден, когда в этом документе есть данные. Данные были переданы из предыдущего мероприятия. Документ был добавлен в базу данных в предыдущем упражнении. Как решить эту проблему? Заранее благодарим.
E/Failed at update: NOT_FOUND: No document to update: projects/secretgarden-9defe/databases/(default)/documents/main/0M0F1Ug5TmcO3pVaZu4XMluGOty1/journal/0M0F1Ug5TmcO3pV
// это ReceivedActivity, который получил данные, переданные из предыдущего действия
public class ReceivedActivity extends AppCompatActivity {
private Journal journal;
private String descText, detectedScoreText, sentencesToneText;
private TextView tonesText, sentencesText;
private FirebaseAuth mAuth;
private FirebaseFirestore db;
private String userId;
private CollectionReference userIdRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_emotion);
tonesText = (TextView) findViewById(R.id.toneText);
sentencesText = (TextView) findViewById(R.id.sentencesText);
//get info passed from other previous activity
journal = (Journal) getIntent().getSerializableExtra("journal");
descText = journal.getDescription();
mAuth = FirebaseAuth.getInstance();
db = FirebaseFirestore.getInstance();
userId = mAuth.getCurrentUser().getUid();
userIdRef = db.collection("main").document(userId).collection("journal");
if (userId == null) {
startActivity(new Intent(EmotionActivity.this, LoginActivity.class));
finish();
} else {
analyzeEmotion();
}
}
private void analyzeEmotion() {
//carry out some action
detectedScoreText = "some string";
sentencesToneText = "some string";
updateFirestoreEmotion();
}
private void updateFirestoreEmotion() {
userIdRef.document(journal.getId())
.update("detected", detectedScoreText, "sentences", sentencesToneText)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(EmotionActivity.this, "Updated detected tones :)", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(EmotionActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
Log.e("Failed at update", e.getMessage());
}
});
}
}
// это структура в firestore (я просто хочу обновить поле «обнаруженные» и «предложения» данными из ReceivedActivity)
// информация, связанная с предыдущей деятельностью
private void addToFirestore() {
String userId = mAuth.getCurrentUser().getUid();
if (!userId.isEmpty()) {
CollectionReference userIdRef = db.collection("main").document(userId).collection("journal");
detectedScoreText = "Not analyzed yet";
sentencesToneText = "Not analyzed yet";
journal = new Journal(userId, title, descText, date, advice, answer, question, detectedScoreText, sentencesToneText);
userIdRef.add(journal).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Intent intent = new Intent(AddNoteActivity.this, ReceivedActivity.class);
intent.putExtra("journal", journal);
startActivity(intent);
finish();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressBar.setVisibility(View.GONE);
Log.e("Failed at saving note", e.getMessage());
showRedSnackbar(e);
}
});
} else {
progressBar.setVisibility(View.GONE);
Log.i("USER MIGHT NOT EXIST", "User ID is empty");
}
}
import com.google.firebase.firestore.ServerTimestamp;
import java.io.Serializable;
import java.util.Date;
public class Journal implements Serializable {
private String id;
private String title;
private String description;
private String advice;
private String answer;
private String question;
public String getDetected() {
return detected;
}
public void setDetected(String detected) {
this.detected = detected;
}
public String getSentences() {
return sentences;
}
public void setSentences(String sentences) {
this.sentences = sentences;
}
private String detected;
private String sentences;
@ServerTimestamp
private Date date;
public Journal(){}
public Journal(String id, String title, String description, Date date, String advice, String answer, String question, String detected, String sentences) {
this.id = id;
this.title = title;
this.description = description;
this.date = date;
this.advice = advice;
this.answer = answer;
this.question = question;
this.detected = detected;
this.sentences = sentences;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAdvice() {
return advice;
}
public void setAdvice(String advice) {
this.advice = advice;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}