5

I have simple layout with ImageView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.vbusovikov.glidetest.MainActivity">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

And simple Glide expression to load an image to this ImageView just to test Glide

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView imageView = (ImageView)findViewById(R.id.image);

        Glide.with(this)
                .load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
                .error(R.mipmap.ic_launcher)
                .into(imageView);

    }

However, error icon is shown. What kind of problem it can be? I have proxy server on my network, and appropriate gradle.properties for that case.

systemProp.http.proxyHost=proxy******.ru
systemProp.http.proxyPort=****

But even if i try to launch this little app outside of any proxies, it won't work for some reason.

My build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.vbusovikov.glidetest"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'

    compile 'com.github.bumptech.glide:glide:3.7.0'

    testCompile 'junit:junit:4.12'
}

UPD. This simple app can load pictures from internet, but it cannot load pictures from my server. Some pictures of my server are being loaded fine, but others are not. I'm lost with this already

TrueCH
  • 501
  • 1
  • 6
  • 18

10 Answers10

9

Unfortunately, all answers were right, but they did not work in my condition. Server settings were not suitable for downloading pictures from it.

==UPDATE==

After a while, I figured out that the pictures on my server were broken. You can check if your picture at provided URL is valid by opening this URL in Mozilla Firefox. The last few kilobytes in pictures may be deleted, but browsers like Google Chrome ignores that and shows image normally. However, Firefox is more sensitive, so it helps to localize the problem.

==UPDATE2==

After another while, I figured out that not only broken pictures can cause the problem. Try add android:usesCleartextTraffic="true" in Manifest in application. It will solve some issues with picture loading.

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
TrueCH
  • 501
  • 1
  • 6
  • 18
  • 1
    I faced same problem .. the images were displayed normally on the browsers but an error appears in Glide library. I tried a lot of solutions and the problem was not solved. My issue has been fixed when i used your solution, thanks – Adel SaadEddin Apr 04 '20 at 14:11
  • Update 2 is working for me but giving a warning about API 22 (my min version). Any other ideas? – paul_f Apr 28 '20 at 22:23
2

Use https insted of http in your image url.

Hiren
  • 1,581
  • 1
  • 12
  • 14
1

I may be too late to answer it, but if someone still faces this issue. So I was stuck with a similar kind of a problem where I couldn't load images using Glide and after alot of research I found out the issue is not from glide but from the image URL. So to solve that I tried using a custom User-Agent and it worked for me.

GlideUrl url = new GlideUrl(imgUrl, new LazyHeaders.Builder()
                    .addHeader("User-Agent", WebSettings.getDefaultUserAgent(mContext))
                    .build());

and use this Url to load the image:

Glide.with(mContext).load(url).into(imageview);
1

I add this attribute to manifest

 <application
       ...
        android:usesCleartextTraffic="true"
       ...>
</application>

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 02 '22 at 11:50
  • You're a bit late with this answer mate :) I've already mentioned cleartext traffic in my own answer in 2019 – TrueCH May 27 '22 at 06:27
0

Try to add placeholder tag too(Looks weird but this fixed me on my side)

Glide.with(YourActivity.this)
                .load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
                .error(R.mipmap.ic_launcher)
                .placeholder(R.mipmap.placeholder)
                .into(imageView);
Ajay Shrestha
  • 2,433
  • 1
  • 21
  • 25
0

The picture might be is too large to be loaded, which might fire an exception: “Bitmap too large to be uploaded into a texture”. In this case image should be scaled before setting it to View (see user1352407's answer)

Copied from user1352407's answer:

ImageView iv  = (ImageView)waypointListView.findViewById(R.id.waypoint_picker_photo);
Bitmap d = new BitmapDrawable(ctx.getResources() , w.photo.getAbsolutePath()).getBitmap();
int nh = (int) ( d.getHeight() * (512.0 / d.getWidth()) );
Bitmap scaled = Bitmap.createScaledBitmap(d, 512, nh, true);
iv.setImageBitmap(scaled);
Amir Golan
  • 378
  • 3
  • 8
0

In my case I'm using a listener, and in onResourceReady I was returning true, but you should return false.

   Glide.with(context)
        .load(url)
        .centerCrop()
        .diskCacheStrategy(DiskCacheStrategy.RESOURCE).listener(object :
            RequestListener<Drawable> {
            override fun onLoadFailed(
                e: GlideException?,
                model: Any?,
                target: Target<Drawable>?,
                isFirstResource: Boolean,
            ): Boolean {
                imageView.visibility = GONE
                errorContainer.visibility = VISIBLE
                return true
            }

            override fun onResourceReady(
                resource: Drawable?,
                model: Any?,
                target: Target<Drawable>?,
                dataSource: DataSource?,
                isFirstResource: Boolean,
            ): Boolean {
                imageView.visibility = VISIBLE
                errorContainer.visibility = GONE
                return false  // <<<<<<<<<<<<<<<<<<<<<<<< here
            }

        }).into(imageView)
MSpeed
  • 8,153
  • 7
  • 49
  • 61
0

Well It happened to me: not showing on the emulator but showing on the real device so I went to settings -> apps on the emulator find your app and UNINSTALL it when you run it again it'll first install it again and voila

cumpatomas
  • 11
  • 1
-1

it is working fine at my side..check the network and don't forgot to add the internet permission in manifest.:)

Pratik Gondil
  • 689
  • 1
  • 6
  • 17
-2

wipe data for the device and It will work perfect