java.lang.IllegalStateException error in Android Sqlite3 "group by" clause -
this query in sqlite3 adb shell:
sqlite> select round prizes group round; 100-7
however, got problem when translating java code:
linkedlist<string> result = new linkedlist<string>(); cursor cursor = db.rawquery("select round prizes group round", null); if(cursor.movetofirst()) { { result.add(cursor.getstring(1)); } while (cursor.movetolast()); } if (cursor != null && !cursor.isclosed()) cursor.close(); return (string[]) result.toarray();
when run code, got error:
error/androidruntime(10540): java.lang.illegalstateexception: field slot row 0 col 1 failed
this because have 1 column returned form query (round
) , index zero-based
see doc getstring
returns value of requested column string. result , whether method throws exception when column value null or column type not string type implementation-defined. parameters
columnindex zero-based index of target column.
the below should work:
result.add(cursor.getstring(0));
Comments
Post a Comment