java.io.FileNotFoundException 和 requestFeature() must be called before adding content
2016-02-09 17:20
561 查看
前言
-今天遇到了两个异常,这里记录下解决方案,怕以后忘记;FileNotFoundException
产生情景:在做聊天功能,接收图片,保存到本地图片的时候;我用Bitmap bitmap= BitmapFactory.decodeFile(getIntent().getStringExtra("bitmap"));
来解析url生成bitmap,然后在保存在本地,路径正确,但发生异常filenotfound,于是改用如下方法解决此异常:
String url = getIntent().getStringExtra("bitmap"); try { InputStream is = new URL( url ).openStream(); bitmap= BitmapFactory.decodeStream(is); } catch (IOException e) { e.printStackTrace(); }
补充
关于BitmapFactory.decodeFile(file) 里面file的路径问题,这个坑坑了我2个小时,终于搞懂了,这里还是记录分享下,免得后人被坑.我们来看看Google官方API是怎么定义file这个参数的.这里官方文档写的,pathName为解析图片文件的完整路径,是没有file://这个东西的哈,应该为/storage/emulated/0/Pictures/Screenshots/S60214-012004.jpg这个完整路径
这里为什么有file://这个前缀呢?因为存在本地数据库的图片路径用ImageLoader.getInstance().displayImage()去加载的时候,需要加file://.请区别开,
否则因为file路径的问题,BitmapFactory.decodeFile(file) 解析失效,将会return一个null.因此程序会报空指针异常.
requestFeature() 异常
在android studio的项目新建activity继承了v7的AppCompactActivity,不能用requestWindowFeature(Window.FEATURE_NO_TITLE);
要用
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
才能去掉标题栏
相关文章推荐
- android异常(2)
- android xml异常:Attribute is missing the Android namespace prefix
- Android Error:main cannot be resolved or is not a field,异常语句:setContentView(R.layout.main);
- android捕获程序异常退出
- 解决方法 android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
- call to OpenGL ES API with no current context (logged once per thread)
- Android异常:Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)'
- Android常见的几种RuntimeException
- 使用EventBus,debug不报错,release版本报错:its super classes have no public methods with the @Subscribe annotat
- exception = android.view.InflateException: Binary XML file line #21: 部分手机正常,部分手机不正常
- You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />
- Android常见的几种RuntimeException
- android studio编程时出现的错误:Error:Execution failed for task ':app:buildInfoDebugLoader'. > Exception whi
- android studio编程时出现的错误:you need to use a theme.appCompat theme(or descendant) with this a
- Android一些小异常
- 解决appcompat-v7:24包的一些坑NotFoundException: File res/drawable-v19/..
- android.content.res.Resources$NotFoundException: String resource ID #0x5848e473
- java.lang.IndexOutOfBoundsException: Invalid index 17, size is 10
- Caused by: java.lang.IllegalStateException: Required view 'descriping' with ID 2131558573 for field
- android.view.InflateException: Binary XML file line #6: Error inflating class com.marshalchen.ultima