The method getResources() is undefined for the type

简介:
在非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了
目录
相关文章
|
Ubuntu 计算机视觉 Python
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
299 0
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
|
6月前
IDEA lombok is undefined for the type
IDEA lombok is undefined for the type
../../..xxx.go:46:18: aa.Bbb undefined (type *"xx/xxx/xx".Ccc has no field or method Bbb)
../../..xxx.go:46:18: aa.Bbb undefined (type *"xx/xxx/xx".Ccc has no field or method Bbb)
The method getServletContext() is undefined for the type HttpServletRequest
The method getServletContext() is undefined for the type HttpServletRequest
227 0
|
5月前
|
前端开发 小程序 JavaScript
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
|
3月前
|
存储 JavaScript 前端开发
成功解决:Cannot read properties of undefined (reading ‘commit‘)
这篇文章提供了解决Vuex中"Cannot read properties of undefined (reading 'commit')"错误的两种方法:检查模板中的数据属性是否存在,以及确保在Vue实例中正确挂载了store对象。
成功解决:Cannot read properties of undefined (reading ‘commit‘)
|
3月前
|
定位技术 Apache
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
86 0
|
3月前
|
JavaScript
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
72 0
|
3月前
|
前端开发 JavaScript
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
64 0

热门文章

最新文章

下一篇
无影云桌面