-1

I get the following error:

Caused by: java.lang.NumberFormatException: Invalid int: "1437061569000"

Full error here.

I have checked whether the string is null, applied the trim() and replace() methods to remove any non integer characters.

The line of the error (42) is the line on which the parseInt method is ran on the string.

Code here:

@Override
protected String doInBackground(String... college) {
    String data_url = "......";
    int lastUpdateTimestamp;
    try {
        String data = DownloadText(data_url).trim().replaceAll( "[^\\d]", "" );
        Log.e("doinback", data);
        if (data == null) { Log.e("doinback", "ITS NULL"); }
        lastUpdateTimestamp = Integer.parseInt(data);
        res = "done";
    } catch (IOException e) {
        res = "ERROR";
    }
    return res;
}
Parsa
  • 3,054
  • 3
  • 19
  • 35
  • please, learn java's basics ... `int` cannot be greater than `Integer.MAX` (2^31 − 1) ... – Selvin Jul 23 '15 at 14:51

3 Answers3

4

That number is too large. The maximum value an int can have is 2^31 - 1. See here.

java.lang.Integer

MAX_VALUE

public static final int MAX_VALUE

A constant holding the maximum value an int can have, 2^31-1.

2^31 - 1 = 2 147 483 647

AutonomousApps
  • 4,229
  • 4
  • 32
  • 42
3

Java Int

Int data type is a 32-bit signed two's complement integer.

Minimum value is - 2,147,483,648.(-2^31)

Maximum value is 2,147,483,647(inclusive).(2^31 -1)

1.437.061.569.000 is way, way bigger than the maximum value.

You need to use a long variable.

Java Long

Long data type is a 64-bit signed two's complement integer.

Minimum value is -9,223,372,036,854,775,808.(-2^63)

Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)

Please read http://www.tutorialspoint.com/java/java_basic_datatypes.htm

Machado
  • 14,105
  • 13
  • 56
  • 97
1

Why don't you use long instead?


The NumberFormatException was thrown because of the Integer value was overlimit. The limit for Integer is from -2,147,483,648 to 2,147,483,647.

If you want to use this number (1437061569000) as your lastUpdateTimestamp variable, you can convert it to long, which has bigger limit than Integer, i.e. from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87