I\'ve seen others come across this problem, but none of the posts have been able to assist me. I\'m attempting to use Volley for my REST call library, and when I\'m attempti
I had the same problem, I fixed it by creating a custom JsonObjectRequest that can catch a null or empty response :
public class CustomJsonObjectRequest extends JsonObjectRequest {
public CustomJsonObjectRequest(int method, String url, JSONObject jsonRequest, Response.Listener listener, Response.ErrorListener errorListener) {
super(method, url, jsonRequest, listener, errorListener);
}
public CustomJsonObjectRequest(String url, JSONObject jsonRequest, Response.Listener listener, Response.ErrorListener errorListener) {
super(url, jsonRequest, listener, errorListener);
}
@Override
protected Response parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
JSONObject result = null;
if (jsonString != null && jsonString.length() > 0)
result = new JSONObject(jsonString);
return Response.success(result,
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
Then just replace the default JsonObjectRequest by this one !