错误代码:
Connected to the target VM, address: '127.0.0.1:60026', transport: 'socket'
java.text.ParseException: Unparseable date: "201801010000"
at java.text.DateFormat.parse(DateFormat.java:366)
at com.atguigu.ct.common.util.DateUtil.parse(DateUtil.java:33)
at com.atguigu.ct.producer.bean.LocalFileProducer.produce(LocalFileProducer.java:60)
at com.atguigu.ct.producer.Bootstrap.main(Bootstrap.java:21)
java.lang.NullPointerException
at com.atguigu.ct.producer.bean.LocalFileProducer.produce(LocalFileProducer.java:60)
at com.atguigu.ct.producer.Bootstrap.main(Bootstrap.java:21)
Disconnected from the target VM, address: '127.0.0.1:60026', transport: 'socket'
Process finished with exit code 0
原代码段为:
public static Date parse(String dateString, String format){
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
其中日期字符串为"201801010101"表示2018年01月01日,0101表示的是时间
format为yyyyMMddhhmmss,报错的原因是0101对应hhmmss不匹配
解决方法一:
时间修改为20180101010101
解决方法二:
format修改为yyyyMMddhhmm