Question

This question already has an answer here:

The following is my code:

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);

I'm able to see the DISPLAY_NAME, but whenever I add PhoneLookup.NUMBER, the application crashes. I also added a condition to select only contacts that have a phone number assuming its crashing due to null data. Still no luck. Is there any permissions I need to add to get the phone number? I already have android.permission.READ_CONTACTS in my manifest.

Logcat output:

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}
Was it helpful?

Solution

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

You are using an invalid name of column.

have a look at this question: How to read contacts on Android 2.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top