0

I have a big String to be converted into Stop objects, but every time I use this function returns a java.lang.NumberFormatException: Invalid int: "1" I don't understand why "1" is not a valid String to be converted in Int...

Where am I wrong?

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;
}

The big String is quite long. I read it from this txt file.

gekoramy bean
  • 151
  • 1
  • 9
  • 2
    Show up the input string and also how `rawToList` is implemented. Help us help you... – Nir Alfasi Jul 29 '17 at 21:36
  • 1
    That String contains more than just that 1, so how about using a debugger to check what that String really contains? – Tom Jul 29 '17 at 21:36
  • Possible duplicate of [What is a NumberFormatException and how can I fix it?](https://stackoverflow.com/questions/39849984/what-is-a-numberformatexception-and-how-can-i-fix-it) – xenteros Aug 08 '17 at 12:15

1 Answers1

3

Solved

I have to remove non-printable unicode characters with this:

string.replaceAll("\\p{C}", "");
gekoramy bean
  • 151
  • 1
  • 9