这个问题在这里已经有一个答案:

以下是我的代码:

Cursor mCursor = this.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER + "==1", null, null);

startManagingCursor(mCursor);

ListAdapter adapter = new SimpleCursorAdapter(this,
    R.layout.two_line_list_item, mCursor, new String[] {
    PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER}, new int[] {R.id.text1, R.id.text2});

setListAdapter(adapter);

我能够看到 DISPLAY_NAME, ,但是每当我添加 PhoneLookup.NUMBER, ,应用程序崩溃。我还添加了一个条件,仅选择具有电话号码的联系人,该联系人由于空数据而崩溃。仍然没有运气。我需要添加任何权限以获取电话号码吗?我已经有了 android.permission.READ_CONTACTS 在我的清单中。

logcat输出:

I/ActivityManager(   58): Starting activity: Intent { cmp=fourth.app/.food }
D/AndroidRuntime(  335): Shutting down VM
W/dalvikvm(  335): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(  335): FATAL EXCEPTION: main
E/AndroidRuntime(  335): java.lang.RuntimeException: Unable to start activity ComponentInfo{fourth.app/fourth.app.food}: java.lang.Ille
galArgumentException: column 'number' does not exist
E/AndroidRuntime(  335):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  335):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  335):        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  335):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  335):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  335):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  335):        at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  335):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  335):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  335):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  335):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  335):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  335): Caused by: java.lang.IllegalArgumentException: column 'number' does not exist
E/AndroidRuntime(  335):        at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
E/AndroidRuntime(  335):        at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
E/AndroidRuntime(  335):        at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)
E/AndroidRuntime(  335):        at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:87)
E/AndroidRuntime(  335):        at fourth.app.food.onCreate(food.java:21)
E/AndroidRuntime(  335):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  335):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  335):        ... 11 more
W/ActivityManager(   58):   Force finishing activity fourth.app/.food
W/ActivityManager(   58):   Force finishing activity fourth.app/.four
W/ActivityManager(   58): Activity pause timeout for HistoryRecord{43f54e88 fourth.app/.food}
有帮助吗?

解决方案

java.lang.IllegalArgumentException: column 'number' does not exist 

您使用的是列的无效名称。

看看这个问题: 如何阅读Android 2.0上的联系人

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top