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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -