【发布时间】:2020-02-01 01:44:14
【问题描述】:
我有一个扫描仪来获取 2 个字符串并将它们更改为 LocalDate 但它没有计算扫描仪并给我这个错误
Exception in thread "main" java.time.format.DateTimeParseException: Text '' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDate.parse(Unknown Source) .....................location of my classes
代码:`
String date1 = sc1.nextLine();
String date2 = sc1.nextLine();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate dateDebut = LocalDate.parse(date1,formatter);
System.out.println(dateDebut);
a1.setDateDeb(dateDebut);
System.out.println(dateFin);
a1.setDateFin(dateFin);
但是当我输入字符串日期(“2019 年 12 月 12 日”)而不是 2 个扫描仪时,它可以工作。
我不知道它来自哪里..我正在使用 Eclipse
【问题讨论】:
-
我无法重现此问题。您遇到错误的具体是哪一行?
-
在打电话给
nextLine之前有没有打电话给nextInt左右? -
是的,我还有其他 2 个参数
-
所以您正在阅读上一行的结尾...可能重复,没有完整代码很难说:stackoverflow.com/a/13102066/85421
-
你是对的,它正在阅读上一行谢谢