0
時遇到錯誤,我正在嘗試檢索電話簿的聯繫人。它似乎查詢沒有返回任何結果,雖然我有存儲在模擬器上的聯繫人。我用下面的代碼:我在嘗試檢索我的應用程序中的聯繫人
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
people.moveToFirst();
while(people.moveToNext()) {
int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
int numberFieldColumnIndex = people.getColumnIndex(PhoneLookup.NUMBER);
String number = people.getString(numberFieldColumnIndex);
Toast.makeText(this, ""+contact+""+number, Toast.LENGTH_LONG);
}
people.close();
錯誤的日誌
E/AndroidRuntime( 277): FATAL EXCEPTION: main
E/AndroidRuntime( 277): java.lang.RuntimeException: Unable to start service [email protected] with Intent { cmp=mobile_security.mobile_security.ui/.getSimCardContacts }: java.lang.IllegalStateException: get field slot from row 1 col -1 failed
E/AndroidRuntime( 277): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
E/AndroidRuntime( 277): at android.app.ActivityThread.access$3600(ActivityThread.java:125)
E/AndroidRuntime( 277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
E/AndroidRuntime( 277): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 277): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 277): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 277): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 277): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 277): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 277): Caused by: java.lang.IllegalStateException: get field slot from row 1 col -1 failed
E/AndroidRuntime( 277): at android.database.CursorWindow.getString_native(Native Method)
E/AndroidRuntime( 277): at android.database.CursorWindow.getString(CursorWindow.java:329)
E/AndroidRuntime( 277): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
E/AndroidRuntime( 277): at android.database.CursorWrapper.getString(CursorWrapper.java:135)
E/AndroidRuntime( 277): at mobile_security.mobile_security.ui.getSimCardContacts.onStart(getSimCardContacts.java:40)
E/AndroidRuntime( 277): at android.app.Service.onStartCommand(Service.java:420)
E/AndroidRuntime( 277): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
E/AndroidRuntime( 277): ... 10 more
我不知道該如何處理這個問題。任何人都可以幫忙THX
哎以及ApplicationConstants不能得到解決。有沒有我需要進口的減稅? – wassim 2011-05-30 05:15:07