The method getResources() is undefined for the type
2015-12-15 16:45
211 查看
在非activity的独立类(public class readwhatsapp)中调用getResources()时(InputStream is = getResources().openRawResource(R.raw.wa_contacts.db)),出现The method getResources() is undefined for the type
这是因为 getResources() 其实是contex中传递过去的,在非activity类中没有找到可以传递的cavas
解决:将activity类中contex传递过去就好了
创建全局变量,用于保存传递过来的context
private Context context;
调用InputStream is = context.getResources().openRawResource(R.raw.wa_contacts.db);就OK了
这是因为 getResources() 其实是contex中传递过去的,在非activity类中没有找到可以传递的cavas
解决:将activity类中contex传递过去就好了
创建全局变量,用于保存传递过来的context
private Context context;
调用InputStream is = context.getResources().openRawResource(R.raw.wa_contacts.db);就OK了
相关文章推荐
- HTML5本地数据库(一)
- 深入理解Java内存模型(二)——重排序
- 关于cell筛选的问题,选中和不选中,解决勾选的问题
- 插入 更新 删除
- MSP430 测量输入电平
- 快速开发平台的报表工具如何自定义页面宽和高?
- 初识MyBatis
- iScroll-js—"smooth scrolling for the web"
- PostgreSQL学习笔记4之常用数据类型
- 最小的k个数
- Bootstrap <第一篇>
- 大型网站架构系列:负载均衡详解(1)
- IOS_3DTouch实现
- 通用表格
- myeclipse xfire客户端调用接口
- js深入研究之Person类案例
- RCE、exp、Exploit、Exploit Pack、exp-gui、Payload、MetaSploit都是啥
- 你刚才淘宝上买衣服---具体分析技术工艺(淘宝页面显示处理的页面)
- Xcode中的几个常用文件路径
- 【django入门教程】Django的安装和入门