Ich habe dieses wirklich seltsame Problem eines kleinen Codeschnippels, das auf einer Maschine funktioniert, und nicht auf einer anderen. Dieser Code:Java - DateTimeFormatter - ParseException
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);
}
gibt mir die Ausnahme:
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)
Die SMHITest.Java:50 Linie ist, wie Sie sich bei der for-Schleife erraten könnte. Der komische Teil ist, dass dieser Code auf einem Computer gut funktioniert, aber er weigert sich, zu Hause für mich zu arbeiten. Beide Maschinen laufen Eclipse Mars Jee, aber eine Maschine (wo es funktioniert) läuft Java 1.8.0_112, und die andere läuft Java 1.8.0_121-b13. Aber ich kann mir nicht vorstellen, dass das das Problem wäre?
die Does "J" von "Jan" muss aktiviert werden? – Keith
Ja, es scheint so, denn das war's! Vielen Dank! Obwohl es immer noch seltsam ist, dass es auf der anderen Maschine nicht notwendig war. Aber krank lass es dort. Danke noch einmal. – Sletten