This is my query in sqlite3 by adb shell:
sqlite> SELECT round FROM prizes GROUP BY round;
100-7
However, I got a problem when translating it into Java code:
LinkedList<String> result = new LinkedList<String>();
Cursor cursor = db.rawQuery("SELECT round FROM prizes GROUP BY round", null);
if(cursor.moveToFirst()) {
do {
result.add(cursor.getString(1));
} while (cursor.moveToLast());
}
if (cursor != null && !cursor.isClosed())
cursor.close();
return (String[]) result.toArray();
When I run this code, I got an error:
ERROR/AndroidRuntime(10540): java.lang.IllegalStateException: get field slot from row 0 col 1 failed
This is because you have only 1 column returned form your query (
round) and the index is zero-basedSee the doc about getString
The below should work: