my my app有问题。一些代码会产生错误:
String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
+ " like'%" + name + "%'";
String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER };
Cursor c = context.getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
selection, null, null);
这是我的错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4321, result=-1, data=Intent { (has extras) }} to activity
...
android.database.sqlite.SQLiteException: near "m": syntax error: , while compiling: SELECT data1 FROM view_data_restricted data WHERE (1 AND mimetype = 'vnd.android.cursor.item/phone_v2') AND (display_name like'%I'm in a pool%')
Caused by: android.database.sqlite.SQLiteException: near "m": syntax error: , while compiling: SELECT data1 FROM view_data_restricted data WHERE (1 AND mimetype = 'vnd.android.cursor.item/phone_v2') AND (display_name like'%I'm in a pool%')
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:245)
Aneone知道出了什么问题?
答案 0 :(得分:0)
AND (display_name like'%I'm in a pool%')
你在I'm
的中间有一个未转义的引号。这就是为什么你的错误抱怨SQLiteException: near "m": syntax error
在插入之前,您需要转义引号。