i am having trouble with Glide from past 2 days. It was working fine but when the update came for Glide depandency it gives me error in my previous code.
here is my code:
private void showImage(Uri uri, int dimenInPx) {
Glide.with(context)
.load(uri)
.override(dimenInPx, dimenInPx)
.transform(new CircleTransform(context))
.placeholder(R.mipmap.ic_display_pic)
.into((ImageView) findViewById(R.id.img_displayPic));
}
.override, .transform and .placeholder is not identifying by Glide.
My Gradle file:
compile 'com.github.bumptech.glide:glide:3.7.0'
Yes i know this is old version, but i even tried with latest version which is...
compile 'com.github.bumptech.glide:glide:4.3.1'
I don't know where i am doing wrong. Please help me out. Thanks
Update 1: I update Glide to latest depandency and then modified my code which is provided by @Ratilal and it looks like this now:
Glide.with(context)
.load(uri)
.apply(new RequestOptions()
.override(dimenInPx, dimenInPx)
.placeholder(R.mipmap.ic_display_pic)
.transform(new CircleTransform(context)))
.into((ImageView) findViewById(R.id.img_displayPic));
So now the error is gone, but i get run time NoSuchMethodError.
No virtual method load(Landroid/net/Uri;)Lcom/bumptech/glide/DrawableTypeRequest; in class Lcom/bumptech/glide/RequestManager; or its super classes (declaration of 'com.bumptech.glide.RequestManager' appears in /data/app/com.scoratech.scoraxchange-1/split_lib_dependencies_apk.apk)
It is simple Glide.with (this), you need to check gradle if you have the correct dependency. If you you are in a enclosing class of a Context (an inner anonymous class such listeners) you need to reference the class outside that is a context so the statement would be: Thanks for contributing an answer to Stack Overflow!
This is a workaround without GlideApp. See github.com/bumptech/glide/issues/1945 to learn how to add GlideApp. If you use Glide package dependencies, compile 'com.github.bumptech.glide:glide:3.7.0', then use should be to use the below code:
use Glide.with(viewholder.itemView.getContext()).clear(viewHolder.getImageView());- this may not solve the OOM's though, but is correct syntax for clearing the image. – Mark Apr 29 '18 at 16:51 2
According to the latest instructions you don't actually need to do ANY of the stuff from the link in the question. You just use "Glide" as normal and you don't have to use "GLideApp". It also doesn't look like you need to setup a custom class or anything like that.
In 4.3.1 you can use like this.
Glide.with(this)
.load(YOUR_URL)
.apply(new RequestOptions().override(dimenInPx, dimenInPx).placeholder(R.drawable.placeHolder).error(R.drawable.error_image))
.into(imageview);
Use latest version with RequestOptions
.
RequestOptions myOptions = new RequestOptions()
.fitCenter()
.override(dimenInPx, dimenInPx);
Glide.with(context)
.load("URL")
.apply(myOptions)
.into(ImageView);
Kindly follow Migrating from v3 to v4
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With