Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCarla Brooks
803 PointsOutOfMemoryError
please I'm having these error on my app... and i don't know why.. here's my LogCat:
java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method) at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:551) at com.example.andrey.login.ImageResizer.resizeImage(ImageResizer.java:28) at com.example.andrey.login.ImageResizer.resizeImageMaintainAspectRatio(ImageResizer.java:57) at com.example.andrey.login.FileHelper.reduceImageForUpload(FileHelper.java:67) at com.example.andrey.login.RecipientsActivity.createMessage(RecipientsActivity.java:143) at com.example.andrey.login.RecipientsActivity.onOptionsItemSelected(RecipientsActivity.java:101)
4 Answers
Adrian Randall
4,807 PointsHow big is your image?
It may not have enough memory allocated depending on how you setup or what your environment is. Or it could be a loop or anything...paste your code from where it's happening
Carla Brooks
803 Pointsit was 2.6 MB
Adrian Randall
4,807 PointsMate that's huge!
If you have Photo Shop save it out as a JPEG and reduce the size of it. Most images that size have massive px heights and widths so resize to what it's going to be displayed at. If you're displaying at 300px by 300px make sure the image isn't 2000px by 2000px..this would give you an Out of Memory Exception in some cases :)
And if it needs an extra bit of love once it's resized (which it shouldnt) you can optimize it here: https://kraken.io/web-interface
If your image has to be super high res then there is a config in Android that allows you to set how much memory is allocated. However I'd recommend against this as it give poor perfromance
Carla Brooks
803 PointsOk now I get it, but my question is how apps like Whatsapp can send and retrieve an image that big?
Adrian Randall
4,807 PointsI don't think they do, I think they compress it for display purposes
OR
If they do they use streaming through sockets instead of brute loading
Google around for "image stream to byte array" or something like that, I haven't done pure Android in ages, been doing Cordova lately
Carla Brooks
803 Pointsok ok thanks man!!! know I understand!!!! God Bless you man!!
Carla Brooks
803 PointsCarla Brooks
803 Pointsi just realize that is the image that was too big, i tries added a smaller image and it worked. But does that mean that i cant send a good image or just a bad quality ones
Adrian Randall
4,807 PointsAdrian Randall
4,807 PointsWhat's it for? And how big was your image?
You should be able to get pretty good resolution images loading with no issues...