Android Picasso Image does not load

Viewed 65491

There are two situations I load images, first, just directly from the internet, and second, load images that are downloaded in the device. And whenever I load, 8~9 out of 10 images are shown, and 1-2 missing. I see that decode returned false, and google'd as hard as I can, but couldn't come up.

  1. WAIT_FOR_CONCURRENT_GC blocked 22ms
  2. WAIT_FOR_CONCURRENT_GC blocked 20ms
  3. GC_FOR_ALLOC freed 718K, 31% free 9948K/14256K, paused 49ms, total 51ms
  4. D/skia: --- decoder->decode returned falseGC_CONCURRENT freed 1370K, 30% free 10081K/14256K, paused 3ms+2ms, total 33ms
  5. GC_FOR_ALLOC freed 916K, 30% free 10029K/14256K, paused 66ms, total 67ms

Here's code I use to load through Picasso:

        Picasso.with(activity)
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);

Any ideas how to solve this issue? I am calling fit()/resize() every time I get the images to load on the screen. Help much appreciated, thanks in advance!

FYI, I test on both machines, emulator and the real device, Samsung Galaxy Tab 3, and works without any problems on emulator, but problems occur on real device.

UPDATE:

It was causing by image's color space, where images that weren't showing up were the ones that were in YMCK color space.

18 Answers

check Internet permission in manifaest

<uses-permission android:name="android.permission.INTERNET"/>

Try to replace "http:" at the start of your Url with "https:" (if it applies)

(on your String representation of Url).replace("http:", "https:");

Works for me.

You can use Picasso.with(Context).setLoggingEnabled(true) to enable debugging so as to troubleshoot the exact cause . If the log has something like Error 504 try using:

android:usesCleartextTraffic="true"

in Application tag of your manifest. It worked for me

Answered here

I was facing the same error, I resized the same image and uploaded it to firebase then load its URL using picasso and this time it worked totally fine; image was loaded successfully.

Same image was not showing nor there were any picasso logs before it was resized.

It took me almost two days to realise that real issue was with image size. I resized my image to 500x500 and everything worked fine.

NOTE: In my case I was capturing image from device's camera then uploading it to firestore and then loading image using picasso. So to fix the issue I started to resize image in onActivityResult() method then save resized image to local storage and uploaded it to firestore.

Make sure your imageUrl contains https instead of http If your imageUrl contain http then creat network_Security_config file under res folder xml folder and mention the URL E.g

    <<network-security-config>
            <domain-config cleartextTrafficPermitted="true">
                <domain includeSubdomains="true">www.your_domain.com</domain>
            </domain-config>
    </network-security-config>

Check if you have these permissions in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>

Maybe this helps someone,

For my url I was using http://localhost:8080/api/get-image/image.jpg...

You need to set instead of localhost, the server's ip!!

//first store the link in string

String url =     
        "https://i.pinimg.com/originals/fc/92/13/fc9213e50a1978c845d7195e988a3322.jpg";
        Picasso.with(this).load(url).into(imageView);

Hope this solution helps someone

Create xml file name network and paste that code in that file

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Add/Include this network.xml file and this line android:usesCleartextTraffic="true" in your Manifest like this

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network"
        android:usesCleartextTraffic="true"

Happy coding, Stay safe

 Picasso.with(activity)
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);

replace it with this below code

 Picasso.get()
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);

Use link below

Picasso.Get().Load(imageUri).Placeholder(Resource.Drawable.patient_profile_pic).Resize(100, 100).Into(imgProflle);

Xamarin or .Net

 byte[] imageBytes;


    using (var webClient = new WebClient())
    {
      imageBytes = webClient.DownloadData(imageUri);
    }

    Bitmap bitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);

    imgProflle.SetImageBitmap(bitmap);

I had faced the same issue but below is the solution which is worked for me.

implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.3.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'

===============================================================================

private static Picasso picasso = null;
public static Picasso.Builder picassoBuilder ;


public static void loadImageInto(Context context, String url, int width, int 
 height, Target target) {
    initPicasso(context);
  picasso.load(url)
            .error(android.R.drawable.stat_notify_error)
            .resize(width, height)
            .centerCrop()
            .into(target);
}

public static void initPicasso(Context context) {
    if (picasso == null) {
         picassoBuilder = new Picasso.Builder(context);

        try {
            Picasso.setSingletonInstance(picasso);
        } catch (IllegalStateException ignored) {
            // Picasso instance was already set
            // cannot set it after Picasso.with(Context) was already in use
        }
        picassoBuilder.downloader(new OkHttpDownloader(new OkHttpClient())).memoryCache(Cache.NONE).loggingEnabled(true).indicatorsEnabled(true);

        picasso = picassoBuilder.build();
        
    }
}

Nobody will be as dumb as me, but for completeness: if you add a tint color to the image view in your layout file it will obscure the successfully loaded image.

Related