2015-07-11 61 views
0

我想從後端使用Volley獲得一個大的JSON。我正在使用JsonObjectRequest和一個單身排球請求隊列來做到這一點。這是我的源:Android Volley - java.lang.OutOfMemoryError

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, 
       URL, new Response.Listener<JSONObject>() { 
      @Override 
      public void onResponse(JSONObject response) { 
       apiResponse.response(response, null); 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) {  
       apiResponse.response(null, error); 
      } 
     }); 

     mRequestQueue.add(request); 

但我總是得到這個異常:

java.lang.OutOfMemoryError 
     at java.util.HashMap.makeTable(HashMap.java:569) 
     at java.util.HashMap.doubleCapacity(HashMap.java:589) 
     at java.util.HashMap.put(HashMap.java:419) 
     at org.json.JSONObject.put(JSONObject.java:263) 
     at org.json.JSONTokener.readObject(JSONTokener.java:385) 
     at org.json.JSONTokener.nextValue(JSONTokener.java:100) 
     at org.json.JSONTokener.readArray(JSONTokener.java:430) 
     at org.json.JSONTokener.nextValue(JSONTokener.java:103) 
     at org.json.JSONTokener.readObject(JSONTokener.java:385) 
     at org.json.JSONTokener.nextValue(JSONTokener.java:100) 
     at org.json.JSONObject.<init>(JSONObject.java:155) 
     at org.json.JSONObject.<init>(JSONObject.java:172) 
     at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:103) 
     at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:123) 

你有任何想法,爲什麼它的崩潰?它可能與我的JSON響應的大小有關嗎?

+0

[http://stackoverflow.com/questions/25868608/volley-framewok-request-keeps-objects-in-memory](http://stackoverflow.com/questions/25868608/volley- framewok-request-keeps-objects-in-memory) –

+0

[https://groups.google.com/forum/#!topic/volley-users/pDBxx-r-YG0](https://groups.google.com/forum /#!topic/volley-users/pDBxx-r-YG0) –

+0

解析海量數據只需使用Gson庫, –

回答