【问题标题】:Unable to load the images in my imageview with Android Picasso无法使用 Android Picasso 在我的图像视图中加载图像
【发布时间】:2020-03-18 11:01:45
【问题描述】:

我需要帮助。我无法在我的图像视图中加载图像;

它给了我以下信息: 日志猫:

2019-11-22 09:02:25.668 10976-10976 / com.acme.crazy W / ImageView: resolveUri 在错误的位图 uri 上失败: https://acme.com/storage/1/1234.png

提前致谢。

马古

public void load(){

        url = "https://acme.com/webservices/json.php?idresp="+IdR+"&idinst="+IdI;
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    JSONArray jsonArray = response.getJSONArray("list");
                    List<Map<String, String>> data = null;
                    data = new ArrayList<Map<String,String>>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        Map<String, String> datanum = new HashMap<String, String>();
                        JSONObject loginApp = jsonArray.getJSONObject(i);
                        datanum.put("A", loginApp.getString("IdA"));
                        datanum.put("B", loginApp.getString("IdI"));
                        datanum.put("C", "https://acme.com/storage/" + loginApp.getString("IdI") + "/" + loginApp.getString("Mat").trim() + ".png");
                        datanum.put("D", loginApp.getString("No"));
                        datanum.put("E", loginApp.getString("Ma"));
                        datanum.put("F", loginApp.getString("Se"));
                        datanum.put("G", loginApp.getString("Sa"));
                        Picasso.get().load(datanum.put( "H", "https://acme.com/storage/" + loginApp.getString("IdI") + "/" + loginApp.getString("Mat").trim() + ".png");
                        data.add(datanum);
                    }
                    String[] from = {"A", "B", "C", "D", "E", "F", "G", "H"};
                    int[] views = {R.id.tvA, R.id.tvB, R.id.tvC, R.id.tvD, R.id.tvE, R.id.tvF, R.id.tvG, R.id.ivSelImgH};
                    AD = new SimpleAdapter(SelectActivity.this, data, R.layout.activity_select_modelo, from, views);
                    lva.setAdapter(AD);

                } catch (JSONException jse){
                    popDialog("Test", "Json Error" + jse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                    popDialog("Tst", "This indicates that the reuest has either time out or there is no connection");
                } else if (error instanceof AuthFailureError) {
                    popDialog("Tst", "Error indicating that there was an Authentication Failure while performing the request");
                } else if (error instanceof ServerError) {
                    popDialog("Tst", "Indicates that the server responded with a error response :" + error.getMessage());
                } else if (error instanceof NetworkError) {
                    popDialog("Tst", "Indicates that there was network error while performing the request");
                } else if (error instanceof ParseError) {
                    popDialog("Tst", "Indicates that the server response could not be parsed");
                }
            }
        });
        mQueue.add(request);
    }

【问题讨论】:

  • 在服务器上没有找到图片我尝试了你的网址但是它给了我404错误,意味着没有找到数据。
  • 我还没有发布应用程序的实际 url 非常感谢您的帮助。实际上我只有在加载图像时使用毕加索时遇到问题。谢了。

标签: android listview imageview picasso


【解决方案1】:

您需要下载图像,然后将其设置为位图。这是众多示例之一。 http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

或者你可以使用Glide,它比毕加索好很多,也很容易上手。

例子:

Glide.with(Activity)
                .load(imageUrl)
                .placeholder(R.drawable.drawable_name)

【讨论】:

    猜你喜欢
    • 2019-08-14
    • 2016-04-08
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 2023-03-28
    • 2019-08-20
    • 2018-06-02
    相关资源
    最近更新 更多