Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (people.moveToNext()){
int NameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
int NumIndex = people.getColumnIndex(PhoneLookup.NUMBER);
String Name = people.getString(NameIndex);
//String Num = people.getString(NumIndex);
myArr.add(Name.toString());
myNum.add(Num.toString());
}
你好我遇到的問題檢索聯繫人的電話號碼,每次我讓這行代碼越來越聯繫人電話號碼
String Num = people.getString(NumIndex);
03-03 15:38:30.436: E/AndroidRuntime(496): FATAL EXCEPTION: main
03-03 15:38:30.436: E/AndroidRuntime(496): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.GhattasAk.RingMe/com.GhattasAk.RingMe.Main}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.os.Looper.loop(Looper.java:123)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-03 15:38:30.436: E/AndroidRuntime(496): at java.lang.reflect.Method.invokeNative(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): at java.lang.reflect.Method.invoke(Method.java:507)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-03 15:38:30.436: E/AndroidRuntime(496): at dalvik.system.NativeStart.main(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWindow.getString_native(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWindow.getString(CursorWindow.java:329)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWrapper.getString(CursorWrapper.java:135)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.GhattasAk.RingMe.Main.onCreate(Main.java:49)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-03 15:38:30.436: E/AndroidRuntime(496): ... 11 more
應用程序崩潰。我不明白爲什麼
這是編輯根據數字得到一個名字是真的嗎?
if(state==TelephonyManager.CALL_STATE_RINGING)
{
// Find contact based on name.
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
"NUMBER = '" + number + "'", null, null);
if (cursor.moveToFirst()) {
String contactId =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
// Get all phone numbers.
Cursor phones = cr.query(Phone.CONTENT_URI, null,
Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
String numb = phones.getString(phones.getColumnIndex(Phone.DISPLAY_NAME));
}
phones.close();
}
cursor.close();
安置自己的logcat的錯誤消息。 – InnocentKiller
好吧我編輯帖子 – user3368764