2015-08-29 50 views
1

當我刪除requestQuery.add()行 - 除網絡數據不存在外,所有工作都正常。加入requestQuery.add()之後 - 我得到這樣的:爲什麼在調用Volley.RequestQuery.add()時出現OutOfMemory異常?

回溯:

08-29 18:15:53.071 6305-7075/? E/dalvikvm-heap﹕ Out of memory on a 840969348-byte allocation. 
    08-29 18:15:53.141 6305-7075/? E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-27227 
     java.lang.OutOfMemoryError 
       at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:322) 
       at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:540) 
       at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:562) 
       at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:403) 
       at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:156) 
       at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:84) 

這裏是我的代碼:

public class DataReceiver { 
    public static void initializeCountriesListUpdate(String urlString, final Context context) throws IOException { 
     RequestQueue requestQueue = Volley.newRequestQueue(context); 
     JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, urlString, 
       new Response.Listener<JSONObject>() { 
        @Override 
        public void onResponse(JSONObject response) { 
         try { 
          ArrayList<Country> countriesList = JsonParser.getCountriesFromJson(response, context); 

          ((CountriesListActivity)context).updateCountriesList(countriesList); 
          ((CountriesListActivity)context).progressDialog.hide(); 
          ((CountriesListActivity)context).progressDialog.dismiss(); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
       }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       Log.e("NetworkManager", "Cannot resolve data from the server"); 
      } 
     }); 
     VolleySingleton.getInstance().getRequestQueue().add(jsonObjectRequest); 
    } 

UPD1:

我試着添加

android:hardwareAccelerated="false" 
    android:largeHeap="true" 

到Manifest,但它沒有幫助。

+0

你分析過你的堆轉儲嗎? – spiderman

+0

我的問題是緩存缺失。感謝Udi提供鏈接提示。這個手冊幫助我make.my singleton正確:https://developer.android.com/training/volley/requestqueue.html#singleton –

回答

1

我會懷疑你的主要問題是內存異常,並作爲一個副作用看到有關ProgressDialog,而試圖在你之後刪除視圖」異常我已經得到了OutOfMemoryError異常(這是「已泄露的窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {41dbc578 VE .... R ...... D 0,0-684,192}那是最初在這裏添加「部分)。

由於主異常表明您的緩存可能比堆大,並且您的服務器響應非常大,您應該專注於解決此問題。

我認爲這個question可能會幫助你解決這個問題。

相關問題