Java 空指针异常 Calendar.setTime

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18269248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:54:24  来源:igfitidea点击:

Null Pointer Exception Calendar.setTime

javacalendarnullpointerexception

提问by BVdjV

  Calendar lastEditDate = Calendar.getInstance();
                        lastEditDate.setTime(rs.getDate("LAST_EDIT_DATE"));
                        productGroup.setLastEditDate(lastEditDate);

I've got a NullPointerException:

我有一个空指针异常:

[ERROR] [16.08.2013 11:30:43] [ DatabaseWorker] = [admin][Get product groups]
java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1106)
at ro.gs.service.catering.dao.ProductGroupDAO.doWork(ProductGroupDAO.java:220)

Can somebody tell me why have I got this exception?

有人能告诉我为什么我有这个例外吗?

采纳答案by Qwerky

getDate(String columnLabel)returns

getDate(String columnLabel)返回

the column value; if the value is SQL NULL, the value returned is null

列值;如果值为 SQL NULL,则返回值为 null

Does your table allow nulls in this column?

您的表是否允许此列中出现空值?

回答by Ruchira Gayan Ranaweera

Because

因为

lastEditDate.setTime(rs.getDate("LAST_EDIT_DATE"));

In here rs.getDate("LAST_EDIT_DATE")is null

这里rs.getDate("LAST_EDIT_DATE")null