Display an image using Glide in Android. Can't see anything

I’m trying to display an image using Glide in my ImageView to no avail. I don’t get any errors, but I don’t see any image either

build.gradle dependencies:

 implementation 'com.github.bumptech.glide:glide:4.12.0'
 annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

my ImageView Layout:

       <ImageView
                    android:id="@+id/profilPicture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/medicine">

       </ImageView>

In my MainActivity I try to display the image within a thread

       val thread = Thread {
        try {
            Glide.with(this)
                .load("http://via.placeholder.com/300.png")
                .into(profilPicture)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    thread.start()

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Glide not required thread.it work on ui thread async manner.also check your image size and internet connection.

Glide.with(this).load(url).into(view);

Solution 2

You dont need to create separate thread for loading because Glide does it for you. Just:

Glide.with(this)
    .load("http://via.placeholder.com/300.png")
    .into(profilPicture)

Will be enough

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply