You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Zishan J." <zi...@programmer.net> on 2016/03/08 13:50:42 UTC

[io] OutOfMemory exception in IOUtils.toByteArray

Hello,
 
I am using Commons.io.IOUtils library in my android application. I have received this error:
 
Fatal Exception: java.lang.OutOfMemoryError
       at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
       at org.apache.commons.io.IOUtils.toByteArray
       at com.alhuda.qih.DownloadCompleteReceiver.onReceive
 
I have tried to catch with IOException but no luck. Is there any way to handle this exception, so I can show the user-friendly message instead of getting the application crashed?
 
Regards,
Zishan J.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [io] OutOfMemory exception in IOUtils.toByteArray

Posted by James Carman <ja...@carmanconsulting.com>.
Do you need the entire thing in memory? What are you trying to do? You
typically can't do much with Errors (which don't extend Exception, but
Throwable) as it means a catastrophic event for the JVM.

On Tue, Mar 8, 2016 at 7:50 AM Zishan J. <zi...@programmer.net> wrote:

> Hello,
>
> I am using Commons.io.IOUtils library in my android application. I have
> received this error:
>
> Fatal Exception: java.lang.OutOfMemoryError
>        at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
>        at org.apache.commons.io.IOUtils.toByteArray
>        at com.alhuda.qih.DownloadCompleteReceiver.onReceive
>
> I have tried to catch with IOException but no luck. Is there any way to
> handle this exception, so I can show the user-friendly message instead of
> getting the application crashed?
>
> Regards,
> Zishan J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

RE: [io] OutOfMemory exception in IOUtils.toByteArray

Posted by Andy Turner <A....@leeds.ac.uk>.
You can try and catch the OutOfMemoryError:

try {
doSomething();
} catch (OutOfMemoryError e) {
Boolean a = true; // Stop the debugger here
}

To handle this really though you want a reserve bit of memory to release and have a way to swap some of your data used by your application from the fast access memory to another store (assuming you need it later, if not just delete all references to it and leave it to garbage collection).

HTH

Andy
http://www.geog.leeds.ac.uk/people/a.turner/index.html
  


-----Original Message-----
From: Julio Oliveira [mailto:julio.juliooliveira@gmail.com] 
Sent: 08 March 2016 13:00
To: Commons Users List <us...@commons.apache.org>
Subject: Re: [io] OutOfMemory exception in IOUtils.toByteArray

Try to use Exception ( this is for all errors )

On Tue, Mar 8, 2016 at 9:50 AM, Zishan J. <zi...@programmer.net> wrote:

> Hello,
>
> I am using Commons.io.IOUtils library in my android application. I 
> have received this error:
>
> Fatal Exception: java.lang.OutOfMemoryError
>        at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
>        at org.apache.commons.io.IOUtils.toByteArray
>        at com.alhuda.qih.DownloadCompleteReceiver.onReceive
>
> I have tried to catch with IOException but no luck. Is there any way 
> to handle this exception, so I can show the user-friendly message 
> instead of getting the application crashed?
>
> Regards,
> Zishan J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


--
Saludos

Julio M. Oliveira - Buenos Aires
http://www.linkedin.com/in/juliomoliveira

Software PYMES - Open Source
http://www.javatango.com/ <http://www.linkedin.com/in/juliomoliveira>

RE: [io] OutOfMemory exception in IOUtils.toByteArray

Posted by Andy Turner <A....@leeds.ac.uk>.
I am not familiar with the Android environment, but another way to solve this issue might be to allow the application to use more memory perhaps by specifying a -Xmx option in the java run command.

Andy


-----Original Message-----
From: Julio Oliveira [mailto:julio.juliooliveira@gmail.com] 
Sent: 08 March 2016 13:00
To: Commons Users List <us...@commons.apache.org>
Subject: Re: [io] OutOfMemory exception in IOUtils.toByteArray

Try to use Exception ( this is for all errors )

On Tue, Mar 8, 2016 at 9:50 AM, Zishan J. <zi...@programmer.net> wrote:

> Hello,
>
> I am using Commons.io.IOUtils library in my android application. I 
> have received this error:
>
> Fatal Exception: java.lang.OutOfMemoryError
>        at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
>        at org.apache.commons.io.IOUtils.toByteArray
>        at com.alhuda.qih.DownloadCompleteReceiver.onReceive
>
> I have tried to catch with IOException but no luck. Is there any way 
> to handle this exception, so I can show the user-friendly message 
> instead of getting the application crashed?
>
> Regards,
> Zishan J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


--
Saludos

Julio M. Oliveira - Buenos Aires
http://www.linkedin.com/in/juliomoliveira

Software PYMES - Open Source
http://www.javatango.com/ <http://www.linkedin.com/in/juliomoliveira>

Re: [io] OutOfMemory exception in IOUtils.toByteArray

Posted by Ayoma Wijethunga <ay...@gmail.com>.
Read through [1] and [2]

"Errors are abnormal conditions that should never occur"  and there is
usually no recovering from it. You can catch it with "OutOfMemoryError"
itself, with "Error" or with "Throwable" [3], if you need and try to
display a message.

Best approach is to check what consumes memory and try to solve the
problem. Android Device Monitor will come in handy with checking relevant
details [4].

[1]
http://javaconceptoftheday.com/difference-between-error-vs-exception-in-java/

[2] https://docs.oracle.com/javase/7/docs/api/java/lang/Error.html
[3]
https://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html
[4] http://developer.android.com/tools/debugging/debugging-memory.html




On Tue, Mar 8, 2016 at 6:29 PM, Julio Oliveira <
julio.juliooliveira@gmail.com> wrote:

> Try to use Exception ( this is for all errors )
>
> On Tue, Mar 8, 2016 at 9:50 AM, Zishan J. <zi...@programmer.net> wrote:
>
> > Hello,
> >
> > I am using Commons.io.IOUtils library in my android application. I have
> > received this error:
> >
> > Fatal Exception: java.lang.OutOfMemoryError
> >        at
> org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
> >        at org.apache.commons.io.IOUtils.toByteArray
> >        at com.alhuda.qih.DownloadCompleteReceiver.onReceive
> >
> > I have tried to catch with IOException but no luck. Is there any way to
> > handle this exception, so I can show the user-friendly message instead of
> > getting the application crashed?
> >
> > Regards,
> > Zishan J.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> >
> >
>
>
> --
> Saludos
>
> Julio M. Oliveira - Buenos Aires
> http://www.linkedin.com/in/juliomoliveira
>
> Software PYMES - Open Source
> http://www.javatango.com/ <http://www.linkedin.com/in/juliomoliveira>
>

Re: [io] OutOfMemory exception in IOUtils.toByteArray

Posted by Julio Oliveira <ju...@gmail.com>.
Try to use Exception ( this is for all errors )

On Tue, Mar 8, 2016 at 9:50 AM, Zishan J. <zi...@programmer.net> wrote:

> Hello,
>
> I am using Commons.io.IOUtils library in my android application. I have
> received this error:
>
> Fatal Exception: java.lang.OutOfMemoryError
>        at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer
>        at org.apache.commons.io.IOUtils.toByteArray
>        at com.alhuda.qih.DownloadCompleteReceiver.onReceive
>
> I have tried to catch with IOException but no luck. Is there any way to
> handle this exception, so I can show the user-friendly message instead of
> getting the application crashed?
>
> Regards,
> Zishan J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
Saludos

Julio M. Oliveira - Buenos Aires
http://www.linkedin.com/in/juliomoliveira

Software PYMES - Open Source
http://www.javatango.com/ <http://www.linkedin.com/in/juliomoliveira>