
the method get content resolver () is undefined for the type
这个错误.
我该如何解决?
以下是代码:
public class ContactManager {public ArrayList<Product> getContactNumber() { Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null); while (phones.movetoNext()) { String name = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.disPLAY_name)); String phoneNumber = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); } phones.close();} }
解决方法 问题是Context,传递Activity的上下文,它在其构造函数中使用了Class:Context context;public ContactManager (Context context) { this.context = context;} 然后用
context.getContentResolver()
这里绝对完善了上下文的使用.
总结以上是内存溢出为你收集整理的android – getcontentresolver()未定义类型全部内容,希望文章能够帮你解决android – getcontentresolver()未定义类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)