I have an ArrayList which I try to convert to String[] so I can query my database but I get outofboundException and I don't know where is the problem?
to convert arraylist to string[] :
String[] idsArray = new String[selectedTopicIds.size()]; idsArray = selectedTopicIds.toArray(idsArray); for (int i = 0; i < selectedTopicIds.size(); i++) { idsArray[i] = selectedTopicIds.get(i); } then I use Cursor to query:
Cursor cursor = myDb.query(Util.TABLE_NAME, null, Util.KEY_TOPIC + "=?", idsArray, null, null, null); and this is how cursor loops:
if (cursor.moveToFirst()) { do { Word word = new Word(); word.setId(cursor.getInt(0)); wordList.add(word); } while (cursor.moveToNext()); } cursor.close(); and on the line that I give it idsArray I have this exception:
java.lang.IllegalArgumentException: Cannot bind argument at index 35 because the index is out of range. The statement has 1 parameters.
both arraylist and String[] must have 35 elements from index 0 to 34
I don't understand where is the problem?
The statement has 1 parameters.means that your query statement contains only one?character.