无法将图像视图传递到Glide

问题描述

我尝试在 ImageView菜单

上从 Glide 加载图像

但它在我的imageView上没有显示图像;

我的图像视图ID是约会对象

从url中的JSON对象加载图像。

在::-

显示错误

Glide.with(this).load(url).into(menagerie);

下面是完整的 代码:-


public void loadMore() {


   String url = "http://my-json-Feed";

   JsonObjectRequest jsonObjectRequest = new JsonObjectRequest 
                                         (Request.Method.get,url,null,new 
                                         Response.Listener<JSONObject>() {
 

        @Override
        public void onResponse(JSONObject response) {

         String url = null;
          try {
           url = response.getString("url");
          } catch (JSONException e) {
           e.printStackTrack();
          }

        Glide.with(this).load(url).into(menagerie);
     }
   }
}


this is my activity.java

解决方法

您在with.(this)处出错

使用getApplicationContext()代替this

您在.into(menagerie)处出错

您永远不要传递ID

您需要初始化变量并将ID传递给它

像这样->

    ImageView ImageView;
    ...
    .
    .
    onCreate()...{
    . 
    .
     ImageView=(ImageView)view.findViewById(R.id.menagerie);


     .
     .

然后您应该执行此操作->

 Glide.with(getApplicationContext())
            .load(url)
            .into(ImageView);
,

改用getApplicationContext(),例如Glide.with(getApplicationContext())。load(imageUrl).into(imageView);