gpt4 book ai didi

android - 查询联系人数据库中的电子邮件时出现语法错误

转载 作者:行者123 更新时间:2023-12-03 08:16:21 26 4
gpt4 key购买 nike

我正在尝试通过联系人数据库搜索电子邮件地址,并在找到该人的情况下获取该人的联系人ID,但是每次尝试都出现语法错误

01-03 17:15:10.574: E/AndroidRuntime(7907): java.lang.RuntimeException: Unable to start receiver com.app.notifyme.GmailReciever: android.database.sqlite.SQLiteException: near "@gmail": syntax error: , while compiling: SELECT raw_contact_id FROM view_data data WHERE (1) AND ((data1=johnsmith@gmail.com))
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2125)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.os.Looper.loop(Looper.java:137)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-03 17:15:10.574: E/AndroidRuntime(7907): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 17:15:10.574: E/AndroidRuntime(7907): at java.lang.reflect.Method.invoke(Method.java:511)
01-03 17:15:10.574: E/AndroidRuntime(7907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-03 17:15:10.574: E/AndroidRuntime(7907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-03 17:15:10.574: E/AndroidRuntime(7907): at dalvik.system.NativeStart.main(Native Method)
01-03 17:15:10.574: E/AndroidRuntime(7907): Caused by: android.database.sqlite.SQLiteException: near "@gmail": syntax error: , while compiling: SELECT raw_contact_id FROM view_data data WHERE (1) AND ((data1=jtopor0910@gmail.com))
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.content.ContentResolver.query(ContentResolver.java:310)
01-03 17:15:10.574: E/AndroidRuntime(7907): at com.app.notifyme.GmailReciever.createNotification(GmailReciever.java:362)
01-03 17:15:10.574: E/AndroidRuntime(7907): at com.app.notifyme.GmailReciever.onReceive(GmailReciever.java:111)
01-03 17:15:10.574: E/AndroidRuntime(7907): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2118)

这是我的查询
Cursor contact = context.getContentResolver().query(Data.CONTENT_URI,new String[] {Data.RAW_CONTACT_ID},Data.DATA1  + "=" + from,null,null);

我的语法有什么问题?它和 @有关系吗?

最佳答案

尝试在电子邮件周围加上引号,即,将方法调用中的第三个参数更改为

Data.DATA1  + "='" + from + "'"

关于android - 查询联系人数据库中的电子邮件时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719499/

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