すべての連絡先を一覧表示する必要があるプロジェクトで作業しています。私はthis articleに従っています。Android java.lang.IllegalArgumentException:連絡先の取得中に_count列が無効です。
マイのAndroidManifest.xmlは以下が含まれ、私は連絡先を読むことができます:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
コードはここにです:
private void getContacts() {
try {
// Form an array specifying which columns to return.
String[] projection = new String[] {
People._ID,
People._COUNT,
People.NAME,
People.NUMBER};
// Get the base URI for the People table in the Contacts content provider.
Uri contacts = People.CONTENT_URI;
// Make the query.
Cursor managedCursor = managedQuery(contacts,
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
// Put the results in ascending order by name
People.NAME + " ASC");
printContacts(managedCursor);
}
catch(Exception ex) {
Log.d("Contacts",ex.toString());
}
}
private void printContacts(Cursor cur){
if (cur.moveToFirst()) {
String name;
String phoneNumber;
int nameColumn = cur.getColumnIndex(People.NAME);
int phoneColumn = cur.getColumnIndex(People.NUMBER);
String imagePath;
do {
// Get the field values
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneColumn);
Log.d("Contacts","Name: "+ name + " **** Phone: "+ phoneNumber);
} while (cur.moveToNext());
}
}
私はエミュレータ(2.3上で実行した場合。 3)以下のエラーが発生する:
java.lang.IllegalArgumentException: Invalid column _count
誰か修正できますか? あなたの貴重な時間のために大変ありがとうございます&ヘルプ。