我试图在Android Studio中调试这段代码。这一切看起来都非常简单,但尝试中的'return sb1'不允许我打破它(带有x的红点)并且说它不可执行。Catch Try让我在Android Studio调试中感到困惑
public static String postRecordOnServer(String url,
ArrayList 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从未被解雇。
有什么建议吗?
+0
它并不总是返回“EXCEPTION”,你可以在'try'部分看到你说的'return sb1;'。 –
+0
通过函数执行is.close(),直接返回“EXCEPTION”,但调用函数返回null。 –
+0
它实际上是否会产生异常? –