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的更多相关文章
- java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题
File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 j ...
- freemarker报 java.io.FileNotFoundException:及TemplateLoader使用
使用过freemarker的肯定其见过如下情况: java.io.FileNotFoundException: Template xxx.ftl not found. 模板找不到.可能你会认为我明明指 ...
- Android java.io.FileNotFoundException:*** (Permission denied)
自从离开上海来到杭州之后,陆续接触了Android,Python,C++,OpenCV,最为一个新人来说,一路上遇到了很多坑,幸运的是 这互联网的强大(大傻子我还是蛮喜欢的哈),一路填填补补总算走了下 ...
- Android代码混淆的问题解决(java.io.FileNotFoundException)
Android Studio(2.3.3) 在给代码混淆时,提示: Warning:Exception while processing task java.io.FileNotFoundExcept ...
- Android下载文件提示文件不存在。。。 java.io.FileNotFoundException
遇到这个错误java.io.FileNotFoundException,事实上文件是存在的,把地址复制到手机浏览器都能够直接下载的,但为嘛不能下载呢. Error in downloadBitmap ...
- android universal image loader 缓冲原理详解
1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL ...
- keytool 错误: java.io.FileNotFoundException: 拒绝访问
keytool 错误: java.io.FileNotFoundException: 拒绝访问 打开命令行,切换到D:\AndroidStudioProjects\MyApplication\app目 ...
- Caused by: java.io.FileNotFoundException
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
- java.io.FileNotFoundException: antlr-2.7.7.jar (系统找不到指定的路径。)[待解决]
严重: Failed to destroy the filter named [struts2] of type [org.apache.struts2.dispatcher.ng.filter.St ...
随机推荐
- 2017-07-20 在Maven Central发布中文API的Java库
知乎原链 相关问题: 哪些Java库有中文命名的API? 且记下随想. 之前没有发布过, 看了SO上的推荐:Publish a library to maven repositories 决定在son ...
- mysql之行(记录)的详细操作
在Mysql管理软件中, 可以通过sql语句中的dml语言来实现数据的操作, 包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用DELETE实现数据的删除 使用SELECT查询数据 ...
- spring配置log4j
1.引入log4j-xxx.jar包,buildpath. 2.在项目的根目录下新建resources名的文件夹,注意是source folder,并新建log4j.properties文件 3.在l ...
- QGIS中坐标偏移处理
to_real("LGTD")+(randf(0.0,1.0)-0.5)*2/1000000.0 getRandomValue() import numpy def getRand ...
- (后端)异常不仅仅是try/catch
前言 编程时我们往往拿到的是业务流程正确的业务说明文档或规范,但实际开发中却布满荆棘和例外情况,而这些例外中包含业务用例的例外,也包含技术上的例外.对于业务用例的例外我们别无它法,必须要求实施人员与 ...
- persist与checkpoint
1.当反复使用某些RDD时建议使用persist(缓存级别)(采用默认缓存级别时为cache())来对数据进行缓存. 2.如果某个步骤的RDD计算特别耗时或经历很多步骤的计算,当重新计算时代价特别大, ...
- python接口测试—get请求(一)
python 做借口测试用到的是requests模块,首先要导入requests库,pip install requests 1.get直接请求方式 以豆瓣网为例: url = 'https://re ...
- 常用css字体英文写法
font-family: 'Microsoft Yahei',sans-serif; 宋体:SimSun 黑体:SimHei
- 用python写个简单的小程序,编译成exe跑在win10上
每天的工作其实很无聊,早知道应该去IT公司闯荡的.最近的工作内容是每逢一个整点,从早7点到晚11点,去查一次客流数据,整理到表格中,上交给素未蒙面的上线,由他呈交领导查阅. 人的精力毕竟是有限的,所以 ...
- Beta冲刺! Day4 - 砍柴
Beta冲刺! Day4 - 砍柴 今日已完成 晨瑶:追进度 昭锡:改主页UI(还在 永盛:完成大部分接口和接口文档,上线代码 立强:文章去广告,适配手机屏幕.第三方编辑器整合到记录模块. 炜鸿:完成 ...