i have to select a random row from a table and display it on buttons and textview… what i am using it …..
Cursor result=sqldb.rawQuery(“SELECT * FROM quiztable ORDER BY RANDOM() LIMIT 1”,null );
String ques=result.getString(1);
String op1=result.getString(2);
String op2=result.getString(3);
String op3=result.getString(4);
String ans=result.getString(5);
txt17.setText(ques);
btn10.setText(op1);
btn11.setText(op2);
btn12.setText(op3);
but the record is not displayed…. i tried try and catch block and display the error using toast …. its say “index -1 requested,with a size 1”
Whts the error in the code?? can any1 tell the solution for it??
thank you in advance ….
You are not moving the cursor on before you take the items from it.
Before the line
Try calling:
The cursor always defaults to position -1, the one before the first record. Both
moveToFirst();ormoveToNext();will get you to the first record.