问题
With this code
public static List<App> findByKeyword(Context context, String keyword){
ContentResolver resolver = context.getContentResolver();
Uri uri = getContentUri();
String[] projection = DataColumns.ALL;
String selection = DataColumns.NAME+" like '%?%' ";
String[] selectionArgs = {keyword};
Cursor cursor = resolver.query(uri, projection, selection, selectionArgs, DEFAULT_ORDER );
return cursorToList(cursor);
}
I get error
Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.
The SQLite raw query should be SELECT * FROM table WHERE name LIKE '%?%'
but there is problem of using parameter though ContentResolver query API
I also tried using "
quotes
String selection = DataColumns.NAME+" like \"%?%\" ";
It also says
The statement has 0 parameters.
回答1:
Try the other way round:
String selection = DataColumns.NAME+" like ? ";
String[] selectionArgs = new String[]{ "%"+keyword+"%" };
hope it helps
来源:https://stackoverflow.com/questions/25932519/android-fails-to-call-sqlite-where-column-like-the-statement-has-0-paramet