【问题标题】:Images Not Loading from URL图片未从 URL 加载
【发布时间】:2016-04-14 03:30:17
【问题描述】:

我正在尝试使用 Picasso 将一些图像加载到列表视图中,但我只看到我的占位符图像。我正在从 RSS 提要加载数据,并且可以确认一切都与我的旧提要 URL 正常工作。两者之间的唯一区别是图像 URL 的格式不同。我正在获取 URL,但我的占位符图像永远不会被 URL 中的图像替换。

在我的片段中:

NodeList nodes = doc.getElementsByTagName("enclosure");
            for (int i = 0; i < nodes.getLength(); i++) {
                Element thumbElement = (Element)nodes.item(i);
                String thumbURL = thumbElement.getAttribute("url");
                if (thumbURL.equals("")) {
                    thumb[i] = "null";
                } else {
                    thumb[i] = thumbURL;
                }
            } 

在我的适配器中:

if (ActionAlertsFragment.thumb[position] != "null") {
            System.out.println(ActionAlertsFragment.thumb[position]);
            Picasso.with(context)
                    .load(ActionAlertsFragment.thumb[position])
                    .placeholder(R.drawable.placeholder)
                    .error(R.drawable.placeholder)
                    .into(holder.thumbnail);
        } else {
            holder.thumbnail.setImageResource(R.drawable.placeholder);
        }

来自新 Feed 的图片网址之一: http://www.kyfb.com/index.cfm/_api/render/file/?fileID=38C277EC-9B70-510A-DE9D93916BAF084C&fileEXT=.jpg

来自旧 Feed 的图片网址: http://kyfbnewsroom.com/wp-content/uploads/2013/01/250px-KY_State_Capitol.jpg

有效的旧提要: http://kyfbnewsroom.com/category/public-affairs/notifications/feed/

不加载图片的新 Feed: https://www.kyfb.com/index.cfm/_api/feed/v1/KYFB/?feedID=61433D1B-DAB1-6572-3CD3CBF8A0142B4B

我开始认为图像不会从新 URL 加载,因为图像 URL 的格式不同并且由于某种原因无法正确加载。旧提要中的图像 URL 按预期工作。

【问题讨论】:

  • 你是否在 manifest.xml 中添加了网络权限?
  • 是的。我可以从 RSS 提要中获取所有其他数据,如果我使用具有不同 URL 的旧版本的提要,一切正常。

标签: android rss picasso


【解决方案1】:

我最终通过将每个 URL 中的“http”替换为“https”来解决此问题

【讨论】:

  • 这也是我的解决方案。
【解决方案2】:

你这里好像有问题

if (ActionAlertsFragment.thumb[position] != "null") {

只需使用“等于”功能,我认为它会起作用

if (!ActionAlertsFragment.thumb[position].equals("null")) {

【讨论】:

    猜你喜欢
    • 2011-08-12
    • 2016-06-20
    • 2018-07-06
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    相关资源
    最近更新 更多