My Project was using Glide V3.7.0. I need to add a listener. But it says Anonymous class derived from RequestListener. I tried updating my glide version. To do this I went to build.gradle: app and simply changed the version number from 3.7.0 to 4.8.0 and performed Gradle sync. But it did not help. Also tried changing Glide.with to GlideApp.with but it doesn't even recognize that keyword...
Glide.with(getApplicationContext())
.load(Uri.parse(url.get((int)(i))))
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(Exception e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false; // important to return false so the error placeholder can be placed
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
.into(IMGS[i]);
I am new to Android Development. Please Help.
Easy Fix : Method 1
To fix this error just place your mouse cursor over new RequestListener() line and press [alt + enter] you will see a prompt and from that select Implement methods.
It will regenerate the methods for you .... and delete old methods
Method 2
Change your glide version in Gradle Use this two dependency
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
and replace your code with below code
Glide.with(getApplicationContext())
.load(Uri.parse(url.get((int)(i))))
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(IMGS[i]);
I recommend you to try the 1st method ...these are the most common problems that you face during development