devapps123
Apple Fan
Profile
Posts: 50
Reg: Jul 12, 2012
Sarasota, FL
500
04/06/14 10:49 AM (10 years ago)

java.lang.OutOfMemoryError...who likes to solve puzzles?

On a recent build for an android app I have not been able to run it on my HTC device because it keeps throwing an error that says "Unfortunately [your app] has stopped." This is a frustratingly vague error message that I'm hoping someone else has solved and/or can shed some light on. I opened the stack trace on my phone and it reports the following: java.lang.OutOfMemoryError:(Heap Size=145256KB, Allocated=136031KB) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:688) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:520) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840) at android.content.res.Resources.loadDrawable(Resources.java:711) at com.myappname.BT_fileManager.getDrawableByName(BT_fileManager.java:263) at com.myappname.BT_viewUtilities$BackgroundImageThread.run(BT_viewUtilities.java:177) My app is actually very light, especially compared with others that I have built without an issue. Here are some specifics for reference on the app: - There are no errors or warnings in Eclipse, so the build is totally clean as far as I can tell. - There are 30 screens: 20 Custom URL, 4 Menu with Image, 3 Call Us, 1 Share Via SMS, 1 Menu Simple, 1 Login - The size on the entire folder is showing on my computer as: "Size: 10.5 MB / Size on Disk: 12.1 MB"
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/06/14 11:16 AM (10 years ago)
It's not an issue of total size of your project - it's an issue of your images. They're probably too large (in dimensions) or too high of resolution. Or you have too many images on a given screen. Android sucks in this regard - especially since every device is different in how it handles the memory.
 
devapps123
Apple Fan
Profile
Posts: 50
Reg: Jul 12, 2012
Sarasota, FL
500
like
04/06/14 12:17 PM (10 years ago)
Hi, Chris. Thank you for replying so quickly. so as far as the images, there are exactly 30 of them, the largest four are2.1MB, 1.2MB, 1.1MB and 1.1 MB. The rest are all under 400KB each with most under 100KB. Would that be enough to cause this error? Is it simply a matter of reducing the file size of the largest 4 images?
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
04/06/14 01:57 PM (10 years ago)
Do you have all your images in res > drawable? If you only have images in that folder, then all devices draw from that folder, and resize as appropriate for the screen size. I've found if I copy all my res > drawable images (except icon.png) to the other res > drawable folders, lots of these crashes go away. Mark
 
devapps123
Apple Fan
Profile
Posts: 50
Reg: Jul 12, 2012
Sarasota, FL
500
like
04/06/14 04:32 PM (10 years ago)
@GoNorthWest Yes, all the images are in Res > Drawable. Thank you for the tip, I'll try that out and update.
 
Arubaman
Aspiring developer
Profile
Posts: 636
Reg: Oct 20, 2011
Akron
16,910
like
04/06/14 09:27 PM (10 years ago)
I had a similar problem with a graphic, did it when I converted the format. To fix it I had to find which one it was and reconvert it from the original.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/07/14 06:15 AM (10 years ago)
2mb is pretty large for an Android image. I've had memory problems with images over 200kb before. Crazy. Reduce them down as much as you can.
 
MM2000
Aspiring developer
Profile
Posts: 207
Reg: Sep 06, 2011
Los Angeles
2,820
like
05/05/14 01:20 PM (10 years ago)
Did anyone find an answer to this? All my images are <100kb (the BT logo), and I'm still getting this error. Thanks!
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.