Android无法调用SQLite WHERE列LIKE'%?%'该语句有0个参数

Pau*_*est 2 sqlite android android-contentresolver

有了这段代码

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);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误

引起:java.lang.IllegalArgumentException:无法绑定索引1处的参数,因为索引超出范围.该语句有0个参数.

应该是SQLite原始查询,SELECT * FROM table WHERE name LIKE '%?%' 但是通过ContentResolver查询API存在使用参数的问题

我也尝试过使用"引号

String selection = DataColumns.NAME+" like \"%?%\" ";
Run Code Online (Sandbox Code Playgroud)

它还说

该语句有0个参数.

zoz*_*lfo 6

反过来尝试:

String selection = DataColumns.NAME+" like ? ";
String[] selectionArgs = new String[]{ "%"+keyword+"%" };
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你