Application de lecture s'écraser PhoneLookup.NUMBER dans Android [double]
-
13-10-2019 - |
Question
Cette question a déjà une réponse ici:
- Comment lire des contacts sur Android 2.0 9 réponses
Ce qui suit est mon 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);
Je suis en mesure de voir le DISPLAY_NAME
, mais chaque fois que j'ajoute PhoneLookup.NUMBER
provoque la panne application. J'ai également ajouté une condition de ne sélectionner que des contacts qui ont un numéro de téléphone assumer son plantage en raison de données null. Toujours pas de chance. Y at-il des autorisations que je dois ajouter pour obtenir le numéro de téléphone? Je l'ai déjà android.permission.READ_CONTACTS
dans mon manifeste.
sortie 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}
La solution
java.lang.IllegalArgumentException: column 'number' does not exist
Vous utilisez un nom incorrect de la colonne.
jeter un oeil à cette question: Comment lire des contacts sur Android 2.0
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow