当前,我正在扫描QR码,然后在Cloud Firestore中更新我的出勤集合。并没有将它们放置在正确的位置,而我正在使用<li class="menu-item">
<form id="menu-item-form">
</form>
<div class="item">Chicken Burger</div>
<span class="fill price">1350.00</span>
<button class="order-btn" form="menu-item-form" type="submit">Add to Order</button>
</li>
类型的模型类。这是我的代码:
Attendance
这是我的出勤模型类代码:我正在创建一个出勤类型的对象,并尝试输入该对象。目前,它们的位置不正确,我已经尝试过更改它们,以使其与考勤构造函数中的外观完全匹配:
final FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
final DocumentReference docRef = rootRef.collection("Session").document(rawValue);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()){
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Date timeToCheck = calendar.getTime();
Session session = document.toObject(Session.class);
Date startTime = session.getStartTime();
Date endTime = session.getEndTime();
if (timeToCheck.after(startTime) && (timeToCheck.before(endTime))) {
Attendance attendance = new Attendance(rawValue, userUID, date, userEmail);
attendanceRef3.add(attendance);
Toast.makeText(StudentAccount.this,
"Your attendance has been recorded", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(StudentAccount.this,
"You are outside the time parameters for this session", Toast.LENGTH_SHORT).show();
}
}
else {
Toast.makeText(StudentAccount.this,
"Session does not exist", Toast.LENGTH_SHORT).show();
它仍然以这种方式出现
答案 0 :(得分:1)
根据您的评论,发生这种情况的原因是,当您使用Attendance
类的对象向数据库添加数据时,您以错误的顺序传递给构造函数值。构造函数声明如下:
public Attendance( String sessionID, String date, String userEmail, String userUID)
因此,当您创建Attendance
类的新对象时,应将以下值传递给构造函数:
Attendance attendance = new Attendance(rawValue, date, userEmail, userUID);
而不是:
Attendance attendance = new Attendance(rawValue, userUID, date, userEmail);
现在在您的代码中。看到正确的顺序了吗?