我有一个非常奇怪的问题,一小段代码在一台机器上工作,而不是另一台。这段代码:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd");
Map<LocalDate, Double> temperatur = new TreeMap<>();
for (LocalDate currentDate = LocalDate.parse("2014-jan-01", formatter); currentDate.getYear() < 2015; currentDate = currentDate.plusDays(1))
{
String date = currentDate.toString();
int stringIndex = (data.indexOf(date));
String tempString = data.substring((stringIndex + 31), (stringIndex + 35));
if(tempString.contains(";"))
tempString = tempString.substring(0, 3);
double temp = Double.parseDouble(tempString);
temperatur.put(currentDate, temp);
}
给我一个例外:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2014-jan-01' could not be parsed at index 5
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDate.parse(Unknown Source)
at main.SMHITest.getValues(SMHITest.java:50)
at main.DataCollectionBuilder.addToResult(DataCollectionBuilder.java:46)
at main.DataCollectionBuilder.<init>(DataCollectionBuilder.java:25)
at main.ClientProgram.main(ClientProgram.java:14)
SMHITest.Java:50 行正如您在 for 循环中可能猜到的那样。奇怪的是,这段代码在一台计算机上运行良好,但拒绝在家里为我工作。两台机器都运行 Eclipse mars jee,但一台机器(它工作的地方)运行 java 1.8.0_112,另一台运行 java 1.8.0_121-b13。但我无法想象那会是问题吗?