我正在尝试将两个csv读入我的Server中。获取NullPointerException,尽管我每次都允许空值并检查null。调试时,即使字符串为null,每次都显示null check表达式计算为FALSE条件。



下面是我的空检查的一个例子:
( row2.Acq_date.equals(null) || row2.Acq_date.equals("") ||
row2.Acq_date == null ) ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")发布于 2018-01-25 16:02:01
您不应该像这个row2.Acq_date.equals(null)那样进行空检查。
这是正确的方法:row2.Acq_date == null (实际上包含在您的测试中,只在测试row2.Acq_date.equals(null)之后才这样做已经太晚了,因为这是抛出NullPointerException的部分)。
以下是正确的方法:
( row2.Acq_date == null ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")基于您的注释,row2.Acq_date是date类型,您可以使用适当的日期格式直接从文件中读取它。如果文件中的列为空(或包含空白空间),Talend将返回一个空日期,该日期由上面的测试处理。
https://stackoverflow.com/questions/48446800
复制相似问题