Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So <code>OutOfMemoryError</code> doesn't mean you are running out of capacity of your file system, it means you are running out of memory that is holding your downloading buffer.</p> <p>In your case, you will need to change your <code>JSONObject.getJSONFromUrl(URL)</code> to manage download buffer on file system but not memory. Here is the example:</p> <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient(); HttpUriRequest request = new HttpGet(url); HttpResponse response = httpClient.execute(request); HttpEntity resEntity = response.getEntity(); InputStream is = null; FileOutputStream fos = null; try { if (resEntity == null) throw new IllegalArgumentException("HTTP entity should not be null."); is = resEntity.getContent(); if (is == null) return 0; // Create parent folder to avoid IOException if (!mBinaryFile.getParentFile().exists()) mBinaryFile.getParentFile().mkdirs(); fos = new FileOutputStream(mBinaryFile, mDownloadedLength!=0); byte[] tmp = new byte[8192]; int bufLength; while((bufLength = is.read(tmp)) != -1) { fos.write(tmp, 0, bufLength); } return mBinaryFile.length(); } catch (IOException e) { throw new ServerConnectionException(R.string.error_network_error, "Download file "+mBinaryFile.getName()+" failed.", e); } finally { Utils.closeStream(is); Utils.closeStream(fos); } </code></pre> <p>In this case, only 8KB memory is needed, so you OOM problem could be solved. But you problem will be turned to how to read JSON data from file system. Just read data you needed piece by piece to avoid <code>OutOfMemoryError</code>, and release memory as soon as you done with it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload