当前位置:网站首页>widget使用setImageViewBitmap方法设置bug分析
widget使用setImageViewBitmap方法设置bug分析
2022-06-30 01:57:00 【帅气好男人_Jack】
widget内ImageView组件设置bitmap问题
在widget里面,Imageview设置bitmap时,通常可以使用
RemoteViews.setImageViewBitmap(R.id.imageview, bitmap)
更新ImageView,使用此方法容易引起以下问题:
AppWidgetHostView: Error inflating RemoteViews : android.widget.RemoteViews$ActionException: android.widget.RemoteViews$ActionException: view: androidx.appcompat.widget.AppCompatImageView can't use method with RemoteViews: setImageBitmap(class android.graphics.Bitmap)
从以上错误日志分析大致意思就是,AppCompatImageView不能在RemoteViews里面使用setImageBitmap这个方法
可是why?remoteViews明明提供了setImageViewBitmap,现在又说不能用
分析一 :这句错误日志“can’t use method with RemoteViews”哪里来的?

method实质就是ImageView的setImageBitmap方法,klass.getName()理论上应该返回的是ImageView,因为我们在layout里面的组件就是ImageView;但是从日志上来说却是AppCompatImageView,这个很关键;还有这句:
method.isAnnotationPresent(RemotableViewMethod.class)
意思是method这个方法上如果有注解,且注解上包含RemotableViewMethod这个类就返回true,不包含就返回false;
我们看看ImageView的setImageBitmap:
确实有,说明ImageView是没有问题的;那从日志侧面反应一个问题,kclass.getName()确实返回不是ImageView而是一个AppCompatImageView
问题原因
明明RemoteViews提供的布局layout里面是一个ImageView,但是在setImageBitmap时却是一个AppCompatImageView;查资料发现大致原因是AppCompatImageView是ImageView的兼容类型,做了很多优化,所以有时候系统会将ImageView替换为AppCompatImageView,而这个AppCompatImageView的setImageBitmap方法没有关于RemotableViewMethod的注解,所以就会报错;
解决
把关于AppCompat的库移除掉,查看build.gradle里面引入了appcomapt库
implementation 'androidx.appcompat:appcompat:1.3.1'
把这行依赖库删除掉,从新编译问题就得到解决了;
边栏推荐
- 207. curriculum - graph theory, depth traversal
- Module import reload method
- 9 — 正则校验集合
- 搞透AQS原理(流程圖及同步隊列圖解)
- Spark 离线开发框架设计与实现
- Want to change careers, but don't know what you want to do?
- Design and implementation of spark offline development framework
- Cookie encryption 10
- Matlab 2012a 绘制带箭头的线段
- Cookie encryption 8
猜你喜欢

搞透AQS原理(流程圖及同步隊列圖解)
![[machine learning Q & A] cosine similarity, cosine distance, Euclidean distance and the meaning of distance in machine learning](/img/34/367c66b8d10e896848b102a7f9aa89.png)
[machine learning Q & A] cosine similarity, cosine distance, Euclidean distance and the meaning of distance in machine learning

cookie加密8

C语言 继续(3n+1)猜想

搞透AQS原理(流程图及同步队列图解)

The first technology podcast month will begin soon

Cookie encryption 15 login encryption

【MySQL 05】SUSE 12 SP5 安装MySQL后第一次修改mysql密码

Application features and functions of painting Aquarium

What should be paid attention to in the design and production of the Urban Planning Museum
随机推荐
Let‘sPlayCurling
OpenCV和Image之间的转换(亲测有效)
搞透AQS原理(流程图及同步队列图解)
MySQL monitoring 6
Pytorch 修改hook源码 获取Per-Layer输出参数(带layer name)
Module import reload method
209. minimum length subarray - sliding window
什么是幂等性?四种接口幂等性方案详解!
ES6 one line code for array de duplication
Summary of DOM
006_ radio
What are the payment and distribution systems?
Oppo mobile phone search
Chiffrement des cookies 8
C语言 继续(3n+1)猜想
Varnish foundation overview 7
Copy entire directory to output folder maintain folder structure- Copy entire directory to output folder maintaining the folder structure?
谁再用Redis过期监听实现关闭订单,立马滚蛋!
Mobaihe cm201-2-ch-hi3798mv300-300h-emmc and NAND_ Infrared Bluetooth voice_ Brush firmware package
[graph neural network] summary of graph classification study [3]: evaluation of graph classification methods and future research directions