Android Universal Image Loader java.io.FileNotFoundException: http:/xxx/lxx/xxxx.jpg

前段时间在使用ImageLoader异步加载服务端返回的图片时总是出现


java.io.FileNotFoundException: http://xxxx/l046/10046137034b1c0db0.jpg

at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)

at com.nostra13.universalimageloader.core.download.URLConnectionImageDownloader.getStreamFromNetwork(URLConnectionImageDownloader.java:40)

at com.nostra13.universalimageloader.core.download.ImageDownloader.getStream(ImageDownloader.java:27)

at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:296)

at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:204)

at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:128)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)

这样的异常。

刚开始没明白怎么回事,于是就开始疯狂的google。最后终于在stackoverflow发下了这个问题的解决方案。这是原文http://stackoverflow.com/questions/14305765/filenotfoundexception-with-universal-image-loader

出现这个错误的原因是:服务端使用的是Apache
提供的开源组件HttpGet和HttpPost。而ImageLoader默认使用的是java再带的原生组件URLHttpConnection。因此在接收和发送数据时会出现解析异常。

解决办法:Android客户端在初始化ImageLoader时将默认的URLHttpConnection改为DefaultHttpClient。

主要代码:


ImageLoaderConfiguration config =
new ImageLoaderConfiguration
.Builder(MainActivity.sharedMainActivity.getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.discCache(new UnlimitedDiscCache(cacheDir))
.threadPoolSize(1)
.memoryCache(new WeakMemoryCache())
.imageDownloader(new HttpClientImageDownloader(new DefaultHttpClient(manager, params)))
.build();

完整初始化代码:


HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it‘s not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 10 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);

// Don‘t handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, "some_randome_user_agent");
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

ImageLoaderConfiguration config =
new ImageLoaderConfiguration
.Builder(MainActivity.sharedMainActivity.getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.discCache(new UnlimitedDiscCache(cacheDir))
.threadPoolSize(1)
.memoryCache(new WeakMemoryCache())
.imageDownloader(new HttpClientImageDownloader(new DefaultHttpClient(manager, params)))
.build();

Android Universal Image Loader java.io.FileNotFoundException:
http:/xxx/lxx/xxxx.jpg

时间: 2024-07-30 10:19:41

Android Universal Image Loader java.io.FileNotFoundException: http:/xxx/lxx/xxxx.jpg的相关文章

java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题

File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问.)at java.io.FileOutputStream.open(Native Method)at java.io.FileOutputStream.<init>(FileOutputStream.ja

freemarker报 java.io.FileNotFoundException:及TemplateLoader使用

使用过freemarker的肯定其见过如下情况: 1 java.io.FileNotFoundException: Template xxx.ftl not found. 模板找不到.可能你会认为我明明指定了文件,并且文件存在,但是为什么就是说找不到呢? 经过研究官方的API,原来freemarker在加载模板时,建议使用TemplateLoader,通过TemplateLoader指定从哪个目录开始加载模板,并且把模板加载在缓存中. API的TemplateLoader是一个接口,他有如下几个

Android下载文件提示文件不存在。。。 java.io.FileNotFoundException

遇到这个错误java.io.FileNotFoundException,事实上文件是存在的,把地址复制到手机浏览器都能够直接下载的,但为嘛不能下载呢. Error in downloadBitmap - http://neirong.funshion.com/download/agc/fcms/疯狂坦克大战/疯狂坦克大战.png : java.io.FileNotFoundException: http://neirong.funshion.com/download/agc/fcms/疯狂坦克大

Play生产模式下java.io.FileNotFoundException那点事

之前”用Scala+Play构建地理数据查询接口”那篇文章里,用到的数据是json格式的文本文件area.json,存放在conf/jsons文件夹下.最开始是放在public/文件夹下,在线上准生产模式下运行: activator dist 得到mosquito-1.0.zip压缩包,解压后: 去/bin目录下运行mosquito脚本报错: java.io.FileNotFoundException 然后就去解压的mosquito-1.0/看发现并没有public文件夹,由此可见public文

keytool 错误: java.io.FileNotFoundException: 拒绝访问

keytool 错误: java.io.FileNotFoundException: 拒绝访问 打开命令行,切换到D:\AndroidStudioProjects\MyApplication\app目录 keytool 在JDK的/bin目录下,比如:/opt/jdk/bin 用以下的命令生成一个证书: keytool -genkey -alias android.key -keyalg RSA -validity 20000 -keystore android.key 老是报如题的错误: 后来

java.io.FileNotFoundException: antlr-2.7.7.jar (系统找不到指定的路径。)[待解决]

严重: Failed to destroy the filter named [struts2] of type [org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter]java.lang.IllegalStateException: java.io.FileNotFoundException: E:\apache-tomcat-8.0.37\webapps\20170317-JavaEE-SSH\WEB-IN

Android Universal Image Loader 使用

1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL. 简单的说 UIL 就做了一件事--获取图片并显示在相应的控件上. 1.2 基本使用 1.2.1 初始化 添加完依赖后在Application或Activity中初始化ImageLoader,如下: public class YourApplication extends Application

java.io.FileNotFoundException: xxx: open failed: EROFS (Read-only file system)

12-21 17:21:13.672: W/System.err(1583): java.io.FileNotFoundException: /downloadedMusic.mp3: open failed: EROFS (Read-only file system) 12-21 17:21:13.672: W/System.err(1583): at libcore.io.IoBridge.open(IoBridge.java:416) 12-21 17:21:13.672: W/Syste

Caused by: java.io.FileNotFoundException

1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help | start | stop } 2014-7-13 0:49:34 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.29 using