0

我在我的android應用程序中使用listView,它有一個textView和一個imageView。 從我想要在imageView中顯示的Web服務URL獲取。 但很多圖片網址未加載。我嘗試了下載圖片URL的「Android通用圖片加載器」和「畢加索」。我使用圖像網址和相同的結果嘗試了這些API示例應用程序。 圖片網址有效。所有圖像都在瀏覽器中打開。 爲什麼有些圖像加載了一些圖像不加載?我不懂爲什麼。 感謝您的回答。通用圖像加載器和畢加索不加載一些圖像的URL

+0

你能發佈更多細節?例如,一些網址 - 最好有一些可以工作,有些則不可以。 – Intrications 2014-09-10 08:37:34

+1

你能告訴我們你的堆棧跟蹤嗎? UIL顯示失敗圖像的日誌錯誤。我們可以從那裏開始 – 2014-09-10 08:37:56

+0

也許在線程上運行多個線程,因此發生某處OutOfMemoryError嘗試在UIL中設置一個線程並將其放置在默認配置中.bitmapConfig(Bitmap.Config.RGB_565)'和'.imageScaleType(ImageScaleType .EXACTLY)' – 2014-09-10 08:39:29

回答

3

問題是,您的服務器正在將請求URL更改爲移動設備,並且移動服務器中不存在圖像。強制UIL使用其他代理應使服務器不重定向您的請求。

您DisplayImageOptions與UIL試試這個

Map<String, String> headers = new HashMap<String, String>(); 
headers.put("User-Agent",""); 
options = new DisplayImageOptions.Builder() 
.showImageOnLoading(R.drawable.dummyhotelimage) 
.showImageForEmptyUri(R.drawable.dummyhotelimage) 
.cacheInMemory(true) 
.cacheOnDisk(true) 
.considerExifParams(true) 
.extraForDownloader(headers) 
.bitmapConfig(Bitmap.Config.RGB_565) 
.imageScaleType(ImageScaleType.EXACTLY) 
.build(); 
ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(getActivity()).imageDownloader(new CustomImageDownloader(context)).build()); 
ImageLoader.getInstance().displayImage(fullImageUrl, holder.img_hotel, options); 

然後創建一個自定義的ImageDownloader

public class CustomImageDownaloder extends BaseImageDownloader { 

    public CustomImageDownaloder(Context context) { 
     super(context); 
    } 

    public CustomImageDownaloder(Context context, int connectTimeout, int readTimeout) { 
     super(context, connectTimeout, readTimeout); 
    } 

    @Override 
    protected HttpURLConnection createConnection(String url, Object extra) throws IOException { 
     HttpURLConnection conn = super.createConnection(url, extra); 
     Map<String, String> headers = (Map<String, String>) extra; 
     if (headers != null) { 
      for (Map.Entry<String, String> header : headers.entrySet()) { 
       conn.setRequestProperty(header.getKey(), header.getValue()); 
      } 
     } 
     return conn; 
    } 
} 

來源:https://github.com/nostra13/Android-Universal-Image-Loader/issues/340

+0

我試過了,但不幸的是沒有工作 – realuser 2014-09-10 10:03:06

+0

堆棧跟蹤看起來是否一樣?帶有m。*。jpg的url的FileNotFoundException? – 2014-09-10 10:04:26

+0

是的正確,看起來堆棧跟蹤相同的錯誤 – realuser 2014-09-10 10:08:14

相關問題