我做了一個簡單的Android應用程序,我需要訪問手機中的聯繫人。無法讀取從CursorWindow行1,col -1
但是我的應用程序崩潰,我得到這個錯誤「無法讀取行1,列-1從CursorWindow」
這裏是日誌:
06-19 11:03:59.582: E/CursorWindow(7926): Failed to read row 1, column -1 from a CursorWindow which has 2 rows, 29 columns. 06-19 11:03:59.611: D/AndroidRuntime(7926): Shutting down VM 06-19 11:03:59.611: W/dalvikvm(7926): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 06-19 11:03:59.842: E/AndroidRuntime(7926): FATAL EXCEPTION: main 06-19 11:03:59.842: E/AndroidRuntime(7926): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.application/com.example.application.Search}: java.lang.IllegalStateException: Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread.access$600(ActivityThread.java:141) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.os.Handler.dispatchMessage(Handler.java:99) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.os.Looper.loop(Looper.java:137) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-19 11:03:59.842: E/AndroidRuntime(7926): at java.lang.reflect.Method.invokeNative(Native Method) 06-19 11:03:59.842: E/AndroidRuntime(7926): at java.lang.reflect.Method.invoke(Method.java:511) 06-19 11:03:59.842: E/AndroidRuntime(7926): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-19 11:03:59.842: E/AndroidRuntime(7926): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-19 11:03:59.842: E/AndroidRuntime(7926): at dalvik.system.NativeStart.main(Native Method) 06-19 11:03:59.842: E/AndroidRuntime(7926): Caused by: java.lang.IllegalStateException: Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.database.CursorWindow.nativeGetString(Native Method) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.database.CursorWindow.getString(CursorWindow.java:434) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.database.CursorWrapper.getString(CursorWrapper.java:114) 06-19 11:03:59.842: E/AndroidRuntime(7926): at com.example.application.Search.onCreate(Search.java:33) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.Activity.performCreate(Activity.java:5104) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 06-19 11:03:59.842: E/AndroidRuntime(7926): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 06-19 11:03:59.842: E/AndroidRuntime(7926): ... 11 more
這裏是代碼:
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
people.moveToFirst();
while(people.moveToNext()) {
int name = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = people.getString(name);
int contact_no = people.getColumnIndex(PhoneLookup.NUMBER);
String number = people.getString(contact_no);
}
people.close();
你錯過了peope.moveToFirst() – Blackbelt
我也加了。但它仍然給出相同的問題 因此我現在從代碼中刪除它。 – drarkayl
沒有數據庫我只是試圖訪問所有聯繫人的姓名和號碼。 – drarkayl