的URI是這樣的:如何查詢單個Uri,然後獲取指向Uri項目的Cursor對象?
com.android.contacts/contacts/lookup/0r431-E08CD8E00524/436
這是我的方式:
Uri entityUri = Uri.withAppendedPath(contactUri, Contacts.Entity.CONTENT_DIRECTORY);
Cursor cursor = resolver.query(entityUri, ContactQuery.COLUMNS, null, null, null);
它總是崩潰!請幫助我,謝謝!
The crash log is below:
V/ContactTileView( 275):
mLookupUricontent://com.android.contacts/contacts/lookup/0r80-29121422/77
V/ContactTileView( 275):
entityUricontent://com.android.contacts/contacts/lookup/0r80-29121422/77/entities
D/AndroidRuntime( 275): Shutting down VM
W/dalvikvm( 275): threadid=1: thread exiting with uncaught exception
(group=0x409f61f8)
I/am_crash( 88):
[275,com.android.contacts,572997,android.database.CursorIndexOutOfBoundsException,Index -1 requested, with a size of 2,AbstractCursor.java,434]
我用直接查找鍵:
Cursor cursor = resolver.query(lookupUri, ContactQuery.COLUMNS, null, null, null);
而崩潰日誌是有點不同:
/ContactTileView( 276):
mLookupUricontent://com.android.contacts/contacts/lookup/0r285-E00EFAE00580/286
D/AndroidRuntime( 276): Shutting down VM
W/dalvikvm( 276): threadid=1: thread exiting with uncaught exception(group=0x409de1f8)
I/content_query_sample( 276): [content://com.android.contacts/contacts/lookup/0r285-E00EFAE00580/286,_id/display_name/display_name_alt/sort_key/starred/contact_presence/contact_status/photo_id/photo_thumb_uri/lookup/phonetic_name/has_phone_number/is_user_profile,,,41,com.android.contacts,9]
I/am_crash( 88):
[276,com.android.contacts,572997,android.database.CursorIndexOutOfBoundsException,Index -1 requested, with a size of 1,AbstractCursor.java,434]
D/dalvikvm( 276): GC_CONCURRENT freed 111K, 3% free 7697K/7879K, paused 2ms+3ms
E/StrictMode( 276): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
E/StrictMode( 276): java.lang.Throwable: Explicit termination method 'close' not called
E/StrictMode( 276): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
E/StrictMode( 276): at android.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1581)
E/StrictMode( 276): at android.content.ContentResolver.query(ContentResolver.java:320)
E/StrictMode( 276): at com.android.contacts.list.ContactTileView.queryForCursor(ContactTileView.java:249)
E/StrictMode( 276): at com.android.contacts.list.ContactTileListContextMenuAdapter.onLongClick(ContactTileListContextMenuAdapter.java:83)
E/StrictMode( 276): at com.android.contacts.list.ContactTileView$2.onLongClick(ContactTileView.java:121)
E/StrictMode( 276): at android.view.View.performLongClick(View.java:3498)
E/StrictMode( 276): at android.view.View$CheckForLongPress.run(View.java:13961)
E/StrictMode( 276): at android.os.Handler.handleCallback(Handler.java:605)
E/StrictMode( 276): at android.os.Handler.dispatchMessage(Handler.java:92)
E/StrictMode( 276): at android.os.Looper.loop(Looper.java:137)
E/StrictMode( 276): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/StrictMode( 276): at java.lang.reflect.Method.invokeNative(Native Method)
E/StrictMode( 276): at java.lang.reflect.Method.invoke(Method.java:511)
E/StrictMode( 276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/StrictMode( 276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/StrictMode( 276): at dalvik.system.NativeStart.main(Native Method)
首先,我認爲我的要求是,我可以得到一個遊標通過查找uri。然後我可以通過這個光標從這個Contact獲得所有的信息。非常感謝。
你的要求說明了什麼? – 2012-04-12 16:37:18
請發佈崩潰堆棧跟蹤 – slayton 2012-04-12 16:58:18