[英]Conflict between two versions with reading contacts in android
I created an application that reads contacts from the phone and it works fine on platform version of 3.1 but it throws NullPointerException when i run it on 2.3.3 platform.Can anyone show me the reason for this error. 我创建了一个可以从电话中读取联系人的应用程序,它在3.1平台版本上可以正常工作,但是在2.3.3平台上运行它时会抛出NullPointerException。有人可以告诉我此错误的原因。
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,null, null, null);
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = cr.query(Phone.CONTENT_URI, null,
Phone.CONTACT_ID + " = " + id, null, null);
while (phones.moveToNext()) {
String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
System.out.println("Numeber= "+number);
switch (type) {
case Phone.TYPE_HOME:
home=number;
break;
case Phone.TYPE_MOBILE:
mobile=number;
break;
case Phone.TYPE_WORK:
work=number;
break;
case Phone.TYPE_OTHER:
other=number;
break;
}
}
phones.close();
}
thanks. 谢谢。
use URI "Phone.CONTENT_URI". 使用URI“ Phone.CONTENT_URI”。 It is being tested for 2.3.3 or 2.2.1. 正在测试2.3.3或2.2.1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.