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");
}
Stringcasadoesn't just contain the number3, it also may contain multiple new line\ncharacters, which cannot be parsed into numbers.String casa = EntityUtils.toString(ht). And remove the while-loop, without appending \n