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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With