我正在尝试使用以下给定代码使用 Android API 2.3 显示联系人姓名和他的电话号码
String[] ContactList= {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone._ID};
//Uri contact =ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Uri contact = Uri.parse("content://contacts/people");
Cursor mycursor = this.managedQuery(contact, ContactList, null, null, null);
int WidgetList[] = {R.id.t1,R.id.t2,R.id.t3};
ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.contactview,mycursor,ContactList,WidgetList);
ListView lv = this.getListView();
lv.setAdapter(adapter);
当我尝试在模拟器中运行它时,出现以下错误
12-01 16:12:03.975: E/AndroidRuntime(403): FATAL EXCEPTION: main
12-01 16:12:03.975: E/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{demo.contentprovider/demo.contentprovider.FirstActivity}: java.lang.IllegalArgumentException: Invalid column data1
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-01 16:12:03.975: E/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 16:12:03.975: E/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507)
12-01 16:12:03.975: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-01 16:12:03.975: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-01 16:12:03.975: E/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
12-01 16:12:03.975: E/AndroidRuntime(403): Caused by: java.lang.IllegalArgumentException: Invalid column data1
12-01 16:12:03.975: E/AndroidRuntime(403): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.content.ContentResolver.query(ContentResolver.java:262)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.Activity.managedQuery(Activity.java:1550)
12-01 16:12:03.975: E/AndroidRuntime(403): at demo.contentprovider.FirstActivity.onCreate(FirstActivity.java:25)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-01 16:12:03.975: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-01 16:12:03.975: E/AndroidRuntime(403): ... 11 more
但是,如果使用
Uri contact =ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
代替
Uri contact = Uri.parse("content://contacts/people");
它可以正常工作。
谁能帮助我为什么它不适用于上述选项。