I am trying to run below code:
Map requestMap = new HashMap<>();
Long unixTime = System.currentTimeMillis() / LONG_1000;
requestM
I traced the stacktrace and I believe that the root cause is response.headers
is null in the method parseNetworkResponse
for some reason. I would suggest the following to confirm this.
StringRequest
In this class override the 'parseNetworkResponse()`. It should look as follows:
protected Response<String> parseNetworkResponse(NetworkResponse response) {
Log.d("Response Header = " + response.headers);
super.parseNetworkResponse(response);
}
Use this class instead of StringRequest
.
Once done, see if the headers is null or not. That should narrow down the problem. By the way, which version of Volley are you using. I never encountered such a problem.
I wrote this on build.gradle.dependencies.
compile 'com.android.volley:volley:1.0.0'
And it worked.
You need to override the parseNetworkResponse
method in StringRequest
and fix a vulnerability which does not anticipate a null header map:
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.getLocalizedMessage());
}
}) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
if (response.headers == null)
{
// cant just set a new empty map because the member is final.
response = new NetworkResponse(
response.statusCode,
response.data,
Collections.<String, String>emptyMap(), // this is the important line, set an empty but non-null map.
response.notModified,
response.networkTimeMs);
}
return super.parseNetworkResponse(response);
}
};
Hope this helps.
I encountered this problem because cidEDTValue was null.
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("CID", cidEDTValue);
return params;
}
}