我正在尝试在 Cloud Firestore 中添加文档,但我需要用于timestamp
添加文档的服务器。文档已成功添加到集合中,并带有正确的timestamp
. 我正在添加带有警告对话框的文档。但是当我返回到我的活动应用程序时,它会因以下错误而终止:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException ....... E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Date com.google.firebase 原因: .Timestamp.toDate()' 在 com.sasam.virtuallibrary.Models.UserLight.setTimestamp(UserLight.java:103) 的空对象引用上
为了显示文档,我正在使用以下查询
Query query= FirebaseFirestore.getInstance()
.collection("Users")
.document(user.getUid())
.collection("friends")
.orderBy("timestamp", Query.Direction.DESCENDING);
我的课在这里
public class UserLight{
protected String name;
protected String email;
protected String uid;
protected Float rating;
protected String photoUrl;
protected long timestamp;
public UserLight(){
}
//other getters and setters
@Exclude
public long getTimestampLong(){
return timestamp;
}
public FieldValue getTimestamp() {
return FieldValue.serverTimestamp();
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp.toDate().getTime();
}
}
HUH函数
相关分类