我有一个很大的String
要转换为Stop
对象,但每次我使用这个函数都会返回一个java.lang.NumberFormatException: Invalid int: “1”
我不明白为什么 "1"
不是要在 Int
中转换的有效 String
...
我哪里错了?
private static List<List<String>> rawToList(String string) {
List<List<String>> result = new ArrayList<>();
for (String row : Arrays.asList(string.split("\n")))
result.add(Arrays.asList(row.split(",")));
result.remove(0);
return result;
}
private static List<Stop> rawToStops(String string) {
List<Stop> stops = new ArrayList<>();
for (List<String> entity : rawToList(string))
stops.add(new Stop(
entity.get(0),
entity.get(1),
entity.get(2),
entity.get(3),
Double.parseDouble(entity.get(4)),
Double.parseDouble(entity.get(5)),
Integer.parseInt(entity.get(6)),
Integer.parseInt(entity.get(7))));
return stops;
}
大字符串
相当长。我从this读到的txt 文件。
最佳答案
已解决
我必须用这个删除不可打印的 unicode 字符:
string.replaceAll("\\p{C}", "");
关于java.lang.NumberFormatException : Invalid int: "1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394270/