I am trying to get the logged in google user's googleID. I am able to get this value as a String object, however I want to be able to store it as a Long object (as in a long integer).
However, when I do this I am greeted with the error:
java.lang.NumberFormatException: Invalid long: "123456789012345678901" at java.lang.Long.invalidLong(Long.java:124) at java.lang.Long.parse(Long.java:364) at java.lang.Long.parseLong(Long.java:352) at java.lang.Long.parseLong(Long.java:318) at java.lang.Long.valueOf(Long.java:476)
The string that I am trying to convert is 21 characters long. Wny is it throwing this error?? What can I do to resolve it?
My code is below
if (Plus.PeopleApi.getCurrentPerson(m_gacGoogleApiClient) != null) {
Person perGooglePerson = Plus.PeopleApi.getCurrentPerson(m_gacGoogleApiClient);
String strGoogleID = perGooglePerson.getId();
Long lonGoogleID = Long.valueOf(strGoogleID);
}
The maximum long
value is 263 - 1 = 9223372036854775807L. Your 21-digit number is way too large to fit in a long
. To avoid the error, you can keep it as a String
or you can use a BigInteger
.
Long.maxValue
is 9,223,372,036,854,775,807.
The string you're trying to parse - 123,456,789,012,345,678,901
- is larger than that, hence your exception.
I am trying to get the logged in Google user's googleID. I am able to get this value as a String object, however I want to be able to store it as a Long object (as in a long integer).
However, when I do this I am greeted with the error:
java.lang.NumberFormatException: Invalid long: "123456789012345678901"
at java.lang.Long.invalidLong(Long.java:124)
at java.lang.Long.parse(Long.java:364)
at java.lang.Long.parseLong(Long.java:352)
at java.lang.Long.parseLong(Long.java:318)
at java.lang.Long.valueOf(Long.java:476)
The string that I am trying to convert is 21 characters long. Why is it throwing this error? What can I do to resolve it?
My code is below
if (Plus.PeopleApi.getCurrentPerson(m_gacGoogleApiClient) != null) {
Person perGooglePerson = Plus.PeopleApi.getCurrentPerson(m_gacGoogleApiClient);
String strGoogleID = perGooglePerson.getId();
Long lonGoogleID = Long.valueOf(strGoogleID);
}