Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android ContentProvider查询条件问题_Android_Sqlite - Fatal编程技术网

android ContentProvider查询条件问题

android ContentProvider查询条件问题,android,sqlite,Android,Sqlite,被Sqlite查询搞糊涂了,这是我的问题,以MediaStore.Audio.Artist.Artist为例 String[] projection={MediaStore.Audio.Artists._ID,MediaStore.Audio.Artists.ARTIST}; String selectionClause=MediaStore.Audio.Artists.ARTIST+" = ?"; String[] selectionArgs={"Artist1","Artist2"}; 只

被Sqlite查询搞糊涂了,这是我的问题,以MediaStore.Audio.Artist.Artist为例

String[] projection={MediaStore.Audio.Artists._ID,MediaStore.Audio.Artists.ARTIST};
String selectionClause=MediaStore.Audio.Artists.ARTIST+" = ?";
String[] selectionArgs={"Artist1","Artist2"};
只想得到匹配字符串“Artist1”和“Artist2”的结果,但我得到的错误如下所示

Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range.  The statement has 1 parameters.

请告诉我有什么问题和正确的做法,谢谢

子句参数中的“?”与参数中的“?”一样多。 在这种情况下,它将类似于:

MediaStore.Audio.Artists.ARTIST+" = ? AND " + MediaStore.Audio.Artists.ARTIST+" = ?";

感谢Emanue和CL,基于他们的想法,以下是解决方案

MediaStore.Audio.Artists.ARTIST+" = ? OR " + MediaStore.Audio.Artists.ARTIST+" = ?";
如您所见,这里您应该使用“或”而不是“和”,如果希望查询的结果与SelectionAgs匹配。 PS.SelectionAgs项目的编号应与selectionClause的编号相同


再次感谢大家

谢谢你的回答,但不幸的是,按照你的回答,游标适配器将不会被调用,不知道为什么?我不知道你所说的“不被调用”是什么意思。请确保您的查询将返回有效结果,然后逐步进行调试抱歉,我的表达式不太清楚,我的意思是,在使用您的idea时,将不会执行CursorAdapter的bindView方法。我在bindView中设置了Log.e命令,并发现Log.e未运行-确保从查询中获得结果-确保用结果数组大小覆盖适配器中的“getCount()”,问题中的“和”实际上是指“或”。