我在 Android 应用程序中有以下代码:
public static HttpResponse dbPost(String handlerUrl, List<NameValuePair> postData) {
HttpClient httpclient = new DefaultHttpClient();
String postUrl = constants.postUrl();
HttpPost httppost = new HttpPost(postUrl);
HttpResponse response = null;
System.out.print("Catch 0");
try {
httppost.setEntity(new UrlEncodedFormEntity(postData));
response = httpclient.execute(httppost);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("Catch 1");
return response;
}
我有一个调用这个块的按钮。如果我按下按钮,控制台将打印“Catch 0”(但不是“Catch 1”)。如果我再次按下按钮(相同的实例),控制台将打印“Catch1Catch0”。有什么问题?
我对Java有点陌生,所以请耐心等待。