I'm creating an Android app, and I'm reading some coordinates from a text file.
I'm using Integer.parseInt(xCoordinateStringFromFile)
to convert the X coordinates to integers, and in the same way with the Y coordinates.
When I run the app, I get an error on that line, which looks like this:
BridgeData data = new BridgeData(
elements[0],
elements[1],
Integer.parseInt(elements[2]),
Integer.parseInt(elements[3]),
Integer.parseInt(elements[4]),
new GeoPos(Integer.parseInt(elements[5].split(",")[0]), Integer.parseInt(elements[5].split(",")[1])),
new GeoPos(Integer.parseInt(elements[6].split(",")[0]), Integer.parseInt(elements[6].split(",")[1])),
Integer.parseInt(elements[7]),
Integer.parseInt(elements[8])
);
The variable elements
is a String array created by splitting the current line on every ;
.
The "main" error is:
java.lang.NumberFormatException: Invalid int: "3546504756"
I wonder what this means, and how I can solve it.
Error just means that java is not able to convert the String that you are trying to use in your call to Integer.pasrseInt
as that number is out of range of an integer.
You should be using Long.parseLong
as 3546504756 number is out of range of an integer.
Make sure post that your BridgeData constructor accepts long as a parameter instead of integer.