This is my site: http://daniandroid.honor.es/getAllCustomers.php when you visit the site, you get a simple text "500".
OK.
final ourHTTP hi = new ourHTTP();
out_string = hi.getWebPage("http://daniandroid.honor.es/getAllCustomers.php");
getWebPage returns the string(content).
int veriff = Integer.parseInt(out_string);
if(veriff>1)
{
final_form.setText("ya");
}
final_form is a TextView on my xml file (activity_second.xml)
Application will crash. ERROR:
at com.android.interval.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: "500"
at java.lang.Integer.parse(Integer.java:375)
If I replace the out_string with this
out_string= "500";
everything is good.
My getAllCustomers.php files contains (source):
<?php
echo"500";
?>
Here is also the method to get the content.
public String getWebPage(String adress)
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet();
InputStream inputStream = null;
String response = null;
try{
URI uri = new URI(adress);
httpGet.setURI(uri);
HttpResponse httpResponse = httpClient.execute(httpGet);
inputStream = httpResponse.getEntity().getContent();
Reader reader = new InputStreamReader(inputStream, "UTF-8");
int inChar;
StringBuffer stringBuffer = new StringBuffer();
while((inChar = reader.read()) != -1){
stringBuffer.append((char)inChar);
}
response = stringBuffer.toString();
}catch(ClientProtocolException e)
{
Log.e(adress, "error");
}catch(IOException e)
{
Log.e(response, "error");
//
}catch(URISyntaxException e)
{
Log.e(response, "error");
}
return response;
}
Integer.parseInt(out_string.replaceAll("[\\D]",""));. I think your HTTP lib passes some non-decimal chars along with the output.