I have a block of code, posting data via HttpPost/HttpCLient. Everything works fine while internet is connected. But when the internet is disconnected or even when something goes wrong on server side, there is no way to handle exception.
I have used all exceptions and catch catch(Exception e) catch (ClientProtocolException e)
but unfortunately none of them worked.
heres the code
@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;
}
Here is the error "Attempt to invoke virtual method 'org.json.JSONObject org.json.JSONArray.getJSONObject(int)' on a null object reference"