这是我的网站:http://daniandroid.honor.es/getAllCustomers.php 当您访问该网站时,您会得到一个简单的文本“500”。Java不会Integer.parseInt(字符串)
好的。
final ourHTTP hi = new ourHTTP();
out_string = hi.getWebPage("http://daniandroid.honor.es/getAllCustomers.php");
getWebPage返回字符串(内容)。
int veriff = Integer.parseInt(out_string);
if(veriff>1)
{
final_form.setText("ya");
}
final_form是我的xml文件(activity_second.xml)一TextView的
应用程序会崩溃。 错误:
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)
如果我这个
out_string= "500";
一切更换out_string好。
我getAllCustomers.php文件包含(来源):
<?php
echo"500";
?>
这里也是获取内容的方法。
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;
}
您是否可能从PHP文件而不是预期的字符串文字返回“”500“”? – andrewdleach
如果您访问该网站,将出现500,同样如果您查看页面源,它将出现500 –
尝试'Integer.parseInt(out_string.replaceAll(“[\\ D]”,“”));'。我认为你的HTTP库传递了一些非十进制字符和输出。 – iTurki