Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:10:51+00:00 2026-06-09T00:10:51+00:00

i have to select a random row from a table and display it on

  • 0

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 ….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:10:54+00:00Added an answer on June 9, 2026 at 12:10 am

    You are not moving the cursor on before you take the items from it.

    Before the line

     String ques=result.getString(1);
    

    Try calling:

    result.moveToFirst();
    

    The cursor always defaults to position -1, the one before the first record. Both moveToFirst(); or moveToNext(); will get you to the first record.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting random row from my table using the following query: SELECT value_id
Possible Duplicate: Select n random rows from SQL Server table I have database and
Let's say I have SELECT name FROM table which gives me something like foo
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have a mysql table and I need to get random row and get
I currently have a linq query to select 5 random rows from my products
I have to extract two random records from a table. I have implemented something
I'm trying to select a random 10% sampling from a small table. I thought
I have a table comparisons. If I run SELECT comparisonID,stu1Vers,stu2Vers,stu1,stu2 from comparisons WHERE stu1!=stu2
I need to take random row from table. At first, i wrote SP like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.