Universal Image Loader抛出UnsupportedOperationException。不知道为什么

时间:2013-05-21 21:18:51

标签: android exception universal-image-loader

似乎所有东西都很好用,但是,UIL不断抛出这个异常。它们不是致命的,也不会崩溃应用程序。我的想法是,当UIL无法找到我通过网络发送它的图像时,UIL就会吐出来。

以下是例外情况。

java.lang.UnsupportedOperationException: UIL doesn't support scheme(protocol) by default [/assets/attachments_missing/avatars/square_missing.png]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))

com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromOtherSource(BaseImageDownloader.java:206)
com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:95)
com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:340)
com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisc(LoadAndDisplayImageTask.java:307)
com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:249)
com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:131)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
java.lang.Thread.run(Thread.java:1019)

这是我对UIL的配置:

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
    .cacheInMemory()
    .cacheOnDisc()
    .showStubImage(R.drawable.wm_new_thumb)
    .showImageOnFail(R.drawable.wm_new_thumb)
    .build();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
    .defaultDisplayImageOptions(defaultOptions)
    .build();

    ImageLoader.getInstance().init(config);

1 个答案:

答案 0 :(得分:2)

如果您想使用Android-Universal-Image-Loader从资源文件夹加载图片,请在资源中附加"assets://"前缀和图片路径:

String imageUri = "assets://attachments_missing/avatars/square_missing.png";
//... do same for other images..

有关更多帮助,请参阅以下有关从资产加载图片的问题:

Does Android-Universal-Image-Loader support Asset folder?