我试图通过 ContactsContract 使用查询获取联系人以下代码引发异常。java.lang.ClassCastException。
public class ContactManager extends Activity{
ArrayList<String> contactsList = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] contacts = getContactNames();
}
public String[] getContactNames(){
try{
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cursor.moveToNext()) {
contactsList.add(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
}
return (String []) contactsList.toArray();
}
catch(Exception e){
Log.e("WOw", e.toString());
return null;
}
}
}
任何的想法?我没有忘记添加权限