【发布时间】:2011-07-01 04:07:21
【问题描述】:
我正在创建一个 android 应用程序,但在找不到(如果?)服务器时,它会挂起工具包(SDK/模拟器?)。 我附上了我的登录代码。请帮助我找到解决方案。我只希望如果服务器不可用,我的应用程序将停留在登录页面上而不会自行挂起。
当我调试我的代码时,我没有得到 httpResponse 的值,在这一行之后
HttpResponse httpResponse = httpclient.execute(httpPost);
问题发生了
public String login(String userName, String password){
try {
String url = URL+ "?flag="+"on"+"&user="+userName+"&pass="+password;
httpPost = new HttpPost(url);
HttpResponse httpResponse = httpclient.execute(httpPost);
int statuscode = httpResponse.getStatusLine().getStatusCode();
if (statuscode == 200) {
String responseMsg = getResponse(httpResponse);
return responseMsg;
}else{
Log.e(TAG, statuscode+"");
}
} catch (ClientProtocolException e) {
Log.e(TAG, e.getMessage(),e);
} catch (IOException e) {
Log.e(TAG, e.getMessage(),e);
}
return null;
}
【问题讨论】:
标签: android