Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide - Cannot resolve method override [duplicate]

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)
like image 960
KhanStan99 Avatar asked Nov 27 '17 12:11

KhanStan99


People also ask

How do I use Glide with a class in a context?

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!

Is there a way to use glide without glideapp?

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:

How do I clear the image in a glide view?

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

Do I need to set up a custom class for glideapp?

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.


2 Answers

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);
like image 95
Ratilal Chopda Avatar answered Oct 21 '22 07:10

Ratilal Chopda


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 .

like image 2
IntelliJ Amiya Avatar answered Oct 21 '22 06:10

IntelliJ Amiya