Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out Of Memory String Android

I am receiving huge JSON and and while I am reading the lines OutOfMemoryError appears.

Here is my first method that I am trying to parse the JSON.

    InputStream in = response.getEntity().getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), 8);
    String result = "";

    while (true) {

                String ss = reader.readLine();
                if (ss == null) {
                        break;
                }
                result += ss;
   }

And I've also tried this method.

    InputStream in = response.getEntity().getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), 8);
    StringBuilder sb = new StringBuilder();
    String line = null;

    while ( (line = reader.readLine()) != null)
    {
    sb.append(line);
    }

In the both of the cases the OutOfMemoryErorr is appearing.

like image 726
Naskov Avatar asked Jan 28 '13 14:01

Naskov


1 Answers

Mostly the error will occur due to heap size. You need to increase the size of the heap

To increase the heap size

For additional info on heap size in java visit here

like image 59
Raja Asthana Avatar answered Oct 27 '22 22:10

Raja Asthana