有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法将imageview传递到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


共 (2) 个答案

  1. # 1 楼答案

    改为使用getApplicationContext(),如下图所示。使用(getApplicationContext())。加载(imageUrl)。进入(图像视图)

  2. # 2 楼答案

    您在with.(this)处出错

    getApplicationContext()代替this

    您在^{处出错

    你不应该通过身份证

    您需要初始化一个变量并向其传递一个id

    像这样>

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

    那么你应该这样做>

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