Java 从文件读取的字符串未解析为localdate

Java 从文件读取的字符串未解析为localdate,java,netbeans,Java,Netbeans,从文件读取的字符串未解析为localdate LocalDate是一个不可变的类,表示默认格式为yyyy-MM-dd的日期。我们可以使用now()方法获取当前日期。我们还可以提供年、月和日期的输入参数来创建LocalDate实例 使用格式化程序解析java.time.LocalDate 'Loans.txt'.java.time.format.DateTimeParseException: Text '2017/11/01' could not be parsed at index 2

从文件读取的字符串未解析为localdate

LocalDate是一个不可变的类,表示默认格式为yyyy-MM-dd的日期。我们可以使用now()方法获取当前日期。我们还可以提供年、月和日期的输入参数来创建LocalDate实例

使用格式化程序解析
java.time.LocalDate

'Loans.txt'.java.time.format.DateTimeParseException: Text '2017/11/01' could not be parsed at index 2
        at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
        at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
        at java.time.LocalDate.parse(LocalDate.java:400)
        at ooad1.Ooad1.main(Ooad1.java:119)
Exception occurred trying to read 'Holder.txt'.
然后,您可以对
setter
方法使用
LocalDate
,之后将不会出现异常

例如


你能用异常更新你的问题吗?打印堆栈跟踪始终记录或打印捕获的异常的堆栈跟踪,该异常未链接到另一个异常。在您的情况下,
catch
块需要包含
e.printStackTrace()。完成后,编辑您的问题并添加完整的堆栈跟踪。您是否目视检查了loans.txt中的数据?也许文件中有一个无效的日期?我已经更新了问题并在放入e.printStackTrace()后复制了输出@SamDev@BillHileman我也在这里复制了我的班级贷款。我在其中使用localdate。
'Loans.txt'.java.time.format.DateTimeParseException: Text '2017/11/01' could not be parsed at index 2
        at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
        at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
        at java.time.LocalDate.parse(LocalDate.java:400)
        at ooad1.Ooad1.main(Ooad1.java:119)
Exception occurred trying to read 'Holder.txt'.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate ldate = LocalDate.parse("2017/11/01", formatter);
setIssueDate(ldate);
setReturnDate(ldate);