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");
}
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.
Comments