求助!这个空指针的bug'boolean android.graphics.Bitmap.compress‘该怎么改?

weixin_39102090 2019-06-18 11:11:18
改了好几天都没找正确修改方法,救命!!!
最近在看一个demo,每当打开系统相册就会报空指针异常

这是异常信息



这是指向的错误代码

换了个不同版本的模拟器,能进去系统相册了,但是单击图片又会报这个空指针异常,到底怎么回事?
所有的权限能加的都加了,是要动态申请权限还是其他问题?该怎么改?卡了好几天,救命!!!
...全文
1567 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
展示的imageView是自定义的吧,在自定义控件的view中重写onDraw方法,在onDraw进行捕获这个异常就ok了。
  • 打赏
  • 举报
回复
估计是版本,权限问题。注意9.0后的手机。
jklwan 2019-06-19
  • 打赏
  • 举报
回复
最好的方法就是debug,一步步走下去,看看压缩bitmap的方法中哪一步有问题,文件是否存在,文件是否有效,宽高是否为0,是否有权限等等。
旅行蜗牛 2019-06-19
  • 打赏
  • 举报
回复
android 7.0 以后不能直接使用 uri.fromfile 参考这个,还有其他配置项百度一下

Uri uri = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    uri = FileProvider.getUriForFile(this, getPackageName() + ".fileProvider", file);
} else {
    uri = Uri.fromFile(file);
}
gxh_apologize 2019-06-19
  • 打赏
  • 举报
回复
引用 9 楼 weixin_39102090 的回复:
[quote=引用 8 楼 gxh_apologize 的回复:] compressImageFromFile返回的bitmap为null
// 数值越高,图片像素越低
    //int inSampleSize = 8;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    //为true的时候不会真正加载图片,而是得到图片的宽高信息。
    //options.inJustDecodeBounds = true;

    options.inSampleSize = inSampleSize;//采样率
    Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
改了还是没效果,不过还是谢谢你哈[/quote]那你调试一下吧,看看这个compressImageFromFile哪行代码有问题,,反正bitmap最后是null 上面的代码是我之前的代码,我是可以生成bitmap的
weixin_39102090 2019-06-18
  • 打赏
  • 举报
回复
[quote=引用 1 楼 leonUI 的回复:]
。。。。。求助
weixin_39102090 2019-06-18
  • 打赏
  • 举报
回复
引用 8 楼 gxh_apologize 的回复:
compressImageFromFile返回的bitmap为null
// 数值越高,图片像素越低
//int inSampleSize = 8;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
//为true的时候不会真正加载图片,而是得到图片的宽高信息。
//options.inJustDecodeBounds = true;

options.inSampleSize = inSampleSize;//采样率
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

改了还是没效果,不过还是谢谢你哈
gxh_apologize 2019-06-18
  • 打赏
  • 举报
回复
compressImageFromFile返回的bitmap为null
// 数值越高,图片像素越低
    //int inSampleSize = 8;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    //为true的时候不会真正加载图片,而是得到图片的宽高信息。
    //options.inJustDecodeBounds = true;

    options.inSampleSize = inSampleSize;//采样率
    Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
weixin_39102090 2019-06-18
  • 打赏
  • 举报
回复
引用 6 楼 旅行蜗牛 的回复:
把你点击事件那里的代码贴出来,问题不在保存这里

旅行蜗牛 2019-06-18
  • 打赏
  • 举报
回复
把你点击事件那里的代码贴出来,问题不在保存这里
weixin_39102090 2019-06-18
  • 打赏
  • 举报
回复
引用 3 楼 jklwan 的回复:
bitmap是null
自己检查下怎么得到bitmap的。

这里咋回事?
weixin_39102090 2019-06-18
  • 打赏
  • 举报
回复
引用 3 楼 jklwan 的回复:
bitmap是null
自己检查下怎么得到bitmap的。

真不知道咋回事,求救啊。。。

jklwan 2019-06-18
  • 打赏
  • 举报
回复
bitmap是null 自己检查下怎么得到bitmap的。

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧