Troubleshooting while loading an image using Picasso Library

OutOfMemoryError Loading Errors 

If an image or set of images aren’t loading, make sure to check the Android monitor log in Android Studio. There’s a good chance you might see a java.lang.OutOfMemoryError “Failed to allocate a […] byte allocation with […] free bytes” or an Out of memory on a 51121168-byte allocation. This is quite common and means that you are loading one or more large images that have not been properly resized. 

First, you have to find which image(s) being loaded are likely causing this error. For any given Picasso call, we can fix this by one or more of the following approaches: 

  1. Add an explicit width or height to the ImageView by setting layout_width=500dp in the layout file and then be sure to call fit() during your load: Picasso.with(…).load(imageUri).fit().into(…)
  2. Open up your static placeholder or error images and make sure their dimensions are relatively small (< 500px width). If not, resize those static images and save them back to your project.
  3. Try removing android:adjustViewBounds=”true” from your ImageView if present and if you are calling .fit() rather than using .resize(width, height)
  4. Call .resize(width, height) during the Picasso load and explicitly set a width or height for the image such as: 
    Picasso.with(…).load(imageUri).resize(500, 0).into(…). By passing 0, the correct height is automatically calculated.


How to Use Picasso Image Loader Library in Android?

Picasso is open source and one of the widely used image download libraries in Android. It is created and maintained by Square. It is among the powerful image download and caching library for Android. Picasso simplifies the process of loading images from external URLs and displays them on your application. For example, downloading an image from the server is one of the most common tasks in any application. And it needs quite a larger amount of code to achieve this via android networking API. By using Picasso, you can achieve this with a few lines of code. 

Similar Reads

How to Use Picasso Android Library?

Step 1: Create an empty activity project...

More Functionalities of the Picasso Library

...

Troubleshooting while loading an image using Picasso Library

...

Contact Us