0

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);
            } 
        } 
Krish
  • 4,166
  • 11
  • 58
  • 110
  • check this issue from [GitHub](https://github.com/google/volley/issues/87) – user 007 Jul 26 '18 at 08:52
  • @User 007 I don't realize the fix was in a snapshot. maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local/' } compile 'com.android.volley:volley:1.0.1-SNAPSHOT' – Krish Jul 26 '18 at 08:59
  • Possible duplicate of [Volley out of memory error, weird allocation attempt](https://stackoverflow.com/questions/24095909/volley-out-of-memory-error-weird-allocation-attempt) – Android Jul 26 '18 at 09:28
  • Possible duplicate of [Volley library getting out of memory error](https://stackoverflow.com/questions/38206161/volley-library-getting-out-of-memory-error) – yogesh lokhande Jul 26 '18 at 10:30

0 Answers0