我正在尝试在 Android Studio 中调试这段代码。这一切看起来都非常简单,但是尝试中的“return sb1”不允许我打破它(带有 x 的红点)并说它不可执行。
public static String postRecordOnServer(String url,
ArrayList<NameValuePair> nameValuePairs) {
String message = "";
InputStream is = null;
try {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine());
String sb1 = sb.toString().toUpperCase();
reader.close();
is.close();
return sb1;
} catch (Exception e) {
message = e.getMessage();
}
return "EXCEPTION:" + message;
}
即使它总是返回 'EXCEPTION' 调用函数得到一个 NULL 结果值。Catch 永远不会被解雇。
有什么建议么?