我有一种将下载日期设置为当前时间的方法。
public class Document {
private DateTime downloadDate;
public void setDownloadDate() {
downloadDate = DateTime.now().withZone(DateTimeZone.UTC);
}
}
返回带有当前下载日期的文档。
public Document getDocument() {
Document document = new Document();
document.setDownloadDate(); // null pointer
return document;
}
文档没有说明withZone可以返回null。例如,当我在测试方法中调用getDocument
时,从setDownloadDate
返回的日期为空。有人知道原因吗?
您的代码中有错字。
[pivate DateTime downloadDate;
实际上应该是private DateTime downloadDate;
。
您的DateTime类的完整软件包是什么?至少在标准JDK中,有Date类或LocalDateTime(自jdk 8起),但没有DateTime类。]