Android Invalid Int error when parsing number from text file

Leonardo

I have a .txt in my website that contains a number (in this case 3) and I use this code to check whether this number is greater than or less than another number, but the code gives me this error:

03-03 16:27:43.734: E/AndroidRuntime(16318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.downloadingprogressbar/com.example.downloadingprogressbar.MainActivity}: java.lang.NumberFormatException: Invalid int: "3

This is my code:

HttpGet httppost = new HttpGet("http://mywebsite.org/version.txt");
    HttpResponse response;
    try {
        response = httpclient.execute(httppost);
        HttpEntity ht = response.getEntity();

        BufferedHttpEntity buf = new BufferedHttpEntity(ht);

        InputStream is = buf.getContent();


        BufferedReader r = new BufferedReader(new InputStreamReader(is));

        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            total.append(line + "\n");
        }
        String casa = new String(total.toString());

        //boolean version = (casa>4);
        if (Integer.parseInt(casa)>4){
            risposta.setText("la tua versione è aggiornata");
        }
        else {
            risposta.setText("aggiorna la tua versione");
        }
Jorgesys

I agree with Kon, your variable "casa" is containing another characters.

Try using the trim() method:

 if (Integer.parseInt(casa.trim())>4){
...
...
...

but now i see that you are appending the "\n", in total variable, is this "new line" necessary?:

 while ((line = r.readLine()) != null) {
            total.append(line);
        }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error invalid int when parsing JSONObject into an integer

From Dev

Invalid date error when parsing

From Dev

fopen outputs invalid argument when passing text file name to it after parsing the name from url which was encoded using urlencode

From Dev

Error when Parsing last position value from text file while streaming data in Julia

From Dev

Invalid int on xml Android color file when launched on a galaxy tab

From Dev

Error occurred while parsing XML content from a text file

From Dev

"invalid conversion from 'FILE* {aka _iobuf}' to 'int'" error

From Dev

Error with XML file - Android(Error parsing XML: not well-formed (invalid token))

From Dev

Invalid character error when parsing JSON

From Dev

Reading text from file and parsing

From Dev

Parsing and split from a text file

From Dev

Error: invalid conversion from 'const int*' to 'int*'

From Dev

Parsing input from stringreader as int fails with invalid syntax

From Dev

how to skip line when parsing text file?

From Dev

Unexpected Behavior when Parsing Text File

From Dev

Error when parsing line of CSV text

From Dev

Xcopy: invalid number of parameters or file not found error

From Dev

Invalid literal error when finding sum of number

From Dev

invalid number error when inserting a row in oracle

From Dev

Python - Parsing multiple lines of text from file

From Dev

Parsing String read from a text file to Integer

From Dev

unexpected error while parsing input invalid uiautomator hierarchy file

From Dev

Error parsing config file when running jshint

From Dev

Unexpected token error when parsing JSX file

From Dev

Error when parsing XML file in Java

From Dev

"Invalid format string" error when parsing date string with Timex in Elixir

From Java

Qt on Android Runtime error: Invalid package identifier when getting bag for resource number 0x00000000

From Java

ValueError: invalid literal for int() with base 10: 'u' occurs when plotting from a specific file

From Java

Internal error parsing svg file in android studio

Related Related

  1. 1

    Error invalid int when parsing JSONObject into an integer

  2. 2

    Invalid date error when parsing

  3. 3

    fopen outputs invalid argument when passing text file name to it after parsing the name from url which was encoded using urlencode

  4. 4

    Error when Parsing last position value from text file while streaming data in Julia

  5. 5

    Invalid int on xml Android color file when launched on a galaxy tab

  6. 6

    Error occurred while parsing XML content from a text file

  7. 7

    "invalid conversion from 'FILE* {aka _iobuf}' to 'int'" error

  8. 8

    Error with XML file - Android(Error parsing XML: not well-formed (invalid token))

  9. 9

    Invalid character error when parsing JSON

  10. 10

    Reading text from file and parsing

  11. 11

    Parsing and split from a text file

  12. 12

    Error: invalid conversion from 'const int*' to 'int*'

  13. 13

    Parsing input from stringreader as int fails with invalid syntax

  14. 14

    how to skip line when parsing text file?

  15. 15

    Unexpected Behavior when Parsing Text File

  16. 16

    Error when parsing line of CSV text

  17. 17

    Xcopy: invalid number of parameters or file not found error

  18. 18

    Invalid literal error when finding sum of number

  19. 19

    invalid number error when inserting a row in oracle

  20. 20

    Python - Parsing multiple lines of text from file

  21. 21

    Parsing String read from a text file to Integer

  22. 22

    unexpected error while parsing input invalid uiautomator hierarchy file

  23. 23

    Error parsing config file when running jshint

  24. 24

    Unexpected token error when parsing JSX file

  25. 25

    Error when parsing XML file in Java

  26. 26

    "Invalid format string" error when parsing date string with Timex in Elixir

  27. 27

    Qt on Android Runtime error: Invalid package identifier when getting bag for resource number 0x00000000

  28. 28

    ValueError: invalid literal for int() with base 10: 'u' occurs when plotting from a specific file

  29. 29

    Internal error parsing svg file in android studio

HotTag

Archive