gpt4 book ai didi

android - 内容提供商错误 : bind or column index out of range: handle 0x234590

转载 作者:搜寻专家 更新时间:2023-11-01 08:10:22 25 4
gpt4 key购买 nike

我已经实现了一个 Content Provider,它导致了以下错误

04-25 00:25:16.856: E/AndroidRuntime(520): Caused by: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x234590

Content Provider中的query是

Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null,
sortOrder);

并且调用 Content Provider 是

cursor = cr.query(uri, new String[] { ContactTableMetaData.ABC,
ContactTableMetaData.MNP }, ContactTableMetaData.XYZ + "=?",
new String[] { "phonenumber1", "phonenumber2", "phonenumber3",
"phonenumber4", "phonenumber5", "email1", "email2", "email3",
"email4", "email5" }, null);

完整的logcat是

04-25 00:25:16.856: E/AndroidRuntime(520): FATAL EXCEPTION: main
04-25 00:25:16.856: E/AndroidRuntime(520): java.lang.RuntimeException: Unable to start activity 04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.os.Looper.loop(Looper.java:123)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 00:25:16.856: E/AndroidRuntime(520): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 00:25:16.856: E/AndroidRuntime(520): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 00:25:16.856: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 00:25:16.856: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 00:25:16.856: E/AndroidRuntime(520): at dalvik.system.NativeStart.main(Native Method)
04-25 00:25:16.856: E/AndroidRuntime(520): Caused by: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x234590
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:241)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:182)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:280)
04-25 00:25:16.856: E/AndroidRuntime(520): at com.wissenways.helper.VoiceAppContactContentProvider.query(VoiceAppContactContentProvider.java:171)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.content.ContentProvider$Transport.query(ContentProvider.java:163)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.content.ContentResolver.query(ContentResolver.java:245)
04-25 00:25:16.856: E/AndroidRuntime(520): at com.wissenways.checkcontacts.DisplayGreatPeople.onCreate(DisplayGreatPeople.java:45)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 00:25:16.856: E/AndroidRuntime(520): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-25 00:25:16.856: E/AndroidRuntime(520): ... 11 more

谢谢。

最佳答案

String selection = ContactTableMetaData.XYZ + "=?";
String[] selectionArgs = new String[] { "phonenumber1", "phonenumber2", "phonenumber3",
"phonenumber4", "phonenumber5", "email1", "email2", "email3",
"email4", "email5" }

? 的数量必须与 selectionArgs 的数量匹配。如果您提供 10 个项目,那么 selection 必须有 10 个 ?

selection 中的第 N 个 ?selectionArgs 中的第 N 个项目替换。

编辑:如果你想检查 ContactTableMetaData.XYZ 是否是其中任何一个,那么要么做

String selection = ContactTableMetaData.XYZ + "=? OR " + ContactTableMetaData.XYZ + "=? OR " + ...

String selection = ContactTableMetaData.XYZ + " IN (?, ?, ?, ?, ..)"

我更喜欢第二个:)

关于android - 内容提供商错误 : bind or column index out of range: handle 0x234590,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10304593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com