5

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)
Zoe
  • 27,060
  • 21
  • 118
  • 148
KhanStan99
  • 414
  • 8
  • 20

2 Answers2

9

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);
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
  • @KhanStan99 what is the issue in this answer. – Ratilal Chopda Nov 27 '17 at 13:23
  • Okay, this is not giving any error, but i am having trouble with OnClick button event. let me resolve that. ill update here once its done. – KhanStan99 Nov 27 '17 at 13:24
  • So here is the update, when i click image pick button it throws this error: FATAL EXCEPTION: main java.lang.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) – KhanStan99 Nov 27 '17 at 16:29
2

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 .

Faruk
  • 5,438
  • 3
  • 30
  • 46
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198