Hi i am using Volley get() method for integrating web services but when i run my code i am getting java.lang.OutOfMemoryError and i tried my level best to resolve this since last 3 days but i am not getting result can some one help me please
Error:-
FATAL EXCEPTION: Thread-12981
java.lang.OutOfMemoryError
at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:316)
at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:526)
at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:549)
at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:392)
at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:155)
at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:85)
code:
RequestQueue queue = Volley.newRequestQueue(context.getApplicationContext());
// String url = ServerUrls.BASE_URL + requestUrl;
Log.i("URL:", "URL:--->" + requestUrl);
StringRequest request = new StringRequest(Request.Method.GET, requestUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
UserNotification.notify(reqType, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
NetworkResponse response = volleyError.networkResponse;
if(response == null) {
if(reqType==Constants.NOTIFICATION_GET_MERCHANTS_LIST_REQUEST) {
UserNotification.
notifyFragment(Constants.NOTIFICATION_HANDLE_ADD_BUTTON_MERCHANTS_LIST,"");
}else{
Utilities.showAlertMessage(AppController.getContext().getResources()
.getString(R.string.network_connection_error), context);
}
}
else {
if (response.statusCode == 401) {
Utilities.showSessionExpiredDialog(context);
} else {
Utilities.showAlertMessage(Constants.VOLLEY_ERROR_SERVER, context);
}
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
try{
Map<String, String> hashMap = new HashMap<>();
hashMap.put("Authorization", "Bearer " + UserPreferences.getPreferenceString(Constants.ATHERIZATION_TOKEN,null));
return hashMap;
}catch (Throwable throwable){
throwable.printStackTrace();
}
return null;
}
@Override
public String getBodyContentType() {
return Constants.CONTENT_TYPE;
}
};
request.setRetryPolicy(new DefaultRetryPolicy(120000, 0, 1.5f));
queue.add(request);
}
}