我有一段代码,通过HttpPost / HttpCLient发布数据。互联网连接时,一切正常。但是当互联网断开连接或服务器端出现问题时,无法处理异常。
我已经使用了所有异常和捕获 catch(例外e) catch(ClientProtocolException e)
但不幸的是,他们都没有工作。
继承人的代码
@Override
protected String doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(_URL);
String responseString = null;
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("data", this._Data));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.w("HTTPRequest", this._Data );
HttpResponse response = httpclient.execute(httppost);
responseString = new BasicResponseHandler().handleResponse(response);
Log.w("HTTPResponse", responseString);
} catch (ClientProtocolException e) {
} catch (IOException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return responseString;
}
这是错误 “尝试在空对象引用上调用虚方法'org.json.JSONObject org.json.JSONArray.getJSONObject(int)'”