How to fix Glide.with(this) issue

38 views
Skip to first unread message

Vishal Kumar

unread,
Jan 13, 2021, 3:20:19 AM1/13/21
to Glide
Hello ,
Here is the section of the code , basically i am trying to make a meme sharing app :

private void loadMeme()
{

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="https://meme-api.herokuapp.com/gimme";

// Request a string response from the provided URL.
JsonObjectRequest JsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url,(String)null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Display the first 500 characters of the response string.
// Log.d("success Request",response.substring(0,500));

String url = null;
try {
url = response.getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
ImageView memeImageView = (ImageView) findViewById(R.id.memeImageView);
Glide.with(this).load(url).into(memeImageView);

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
//Throwable e = null;
//Log.d("error response: ", Objects.requireNonNull(e.getLocalizedMessage()));;

}
});

Glide.with(this).load(url).into(memeImageView);  is the line which is showing this error message 
Cannot resolve method 'with(anonymous com.android.volley.Response.Listener<org.json.JSONObject>)' 

how to fix it

Róbert Papp

unread,
Jan 13, 2021, 12:58:07 PM1/13/21
to Glide
Hi!
If loadMeme is a member of a class called MemeActivity then Glide.with(MemeActivity.this) will work. I recommend you take a look at https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html#shadowing. In your case you're inside onResponse method whose "this" is the anonymous inner class instance created with new Response.Listener() { ... }.
Reply all
Reply to author
Forward
0 new messages