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 9102589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:25:14+00:00 2026-06-17T01:25:14+00:00

I made an application that generates random word from database. But there is a

  • 0

I made an application that generates random word from database. But there is a problem like that:
I insert some rows into the database and ID field is AUTOINCREMENT. I get a random word from database. But, when I delete a record and I insert the new one, as you know, the ID is skipping the old one.
So, when I try to get a random word, it may make an error occured. How can I solve this problem?
Thank you for your responds…

public void kelimeUret() {

    SQLiteDatabase db = kelimeler.getReadableDatabase();

    rastgele = new Random();

    Cursor kayit = db.rawQuery("SELECT count(*) FROM kelimeler", null);

    kayit.moveToFirst();

    int max = Integer.parseInt(kayit.getString(0));
    int min = 1;

    int rastgeleKayit = rastgele.nextInt(max - min + 1) + min;

    Cursor kayit2 = db.rawQuery("SELECT ingilizce FROM kelimeler WHERE id=" + rastgeleKayit, null);

    kayit2.moveToFirst();
    String sonuc = kayit2.getString(0);

    olusturulanKelime = sonuc;

    kelime = (TextView) findViewById(R.id.kelime);
    kelime.setText(sonuc);

}

My code is here. Actually there is no problem. It works. But when random generates an ID that has been removed from database before, it gives error. I thought that I should generate an ordered numbers for records, but I couldn’t find the way to do that. I want to do it in another way. (Not on ID)

  • 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-17T01:25:15+00:00Added an answer on June 17, 2026 at 1:25 am

    Your easiest bet is probably to drop the AUTOINCREMENT if you can, and instead handle giving an ID by yourself.
    Just query for the highest current ID and increment it yourself.

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

Sidebar

Related Questions

I made an application that generates reports based on data from a database. The
I have a following problem. I made an application that generates rdlc reports for
I have made a java application that stores data from a .csv file to
I've made an application that takes tagged versions of a project from an hg
I made an application in C# Visual Studio 2010 that generates reports about the
I've made an application that uses another company's exe to generate some output files
I made an application that passes trough an XML file and extracts the entries
I have made an application that gives the user the option to open up
I've made an application that makes full use of ajax, and what I need
I made a SmartDevice application that runs on startup and I want it to

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.