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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:19:47+00:00 2026-05-26T00:19:47+00:00

So I’m working on a game for android and I’m currently stuck at the

  • 0

So I’m working on a game for android and I’m currently stuck at the ‘load savegame’ button in the main menu.
This button calls methods that read data from the database and write it into a resource class from which on this data will be accessed.

The problem is: I want to disable the load button if there are no rows in the tables, which means that no savegame exists.

To do this I used the following method:

public boolean checkForTables(){
    boolean hasTables;
    String[] column = new String[1];
    column[0] = "Position";
    Cursor cursor;
    cursor = db.query("itemtable", column, null, null, null, null, null);
    if(cursor.isNull(0) == true){
        hasTables=false;
    }else{
        hasTables=true;
    }
    return hasTables;

As you can see it starts a query on one of the database tables and checks if the 0-column, which is the only one that should be in this cursor, is null. ATM I can’t check logcat results on this call because I seem to have some problems with it, but it seems that the query throws an exception because the table is empty.

Any idea to check the tables for rows?

____________________EDIT______________

NOTE: I checked the database and it sure is empty

Okay I used a rawQuery on the table but the approach with count-statement produced an error, so I’m using

public boolean checkForTables(){
        boolean hasTables;

        Cursor cursor = db.rawQuery("SELECT * FROM playertable", null);

        if(cursor.getCount() == 0){
            hasTables=false;
        if(cursor.getCount() > 0){
            hasTables=true;
        }

        cursor.close();
        return hasTables;
    }

I’m using this method to decide whether or not to disable the loadGame-button which looks like this:

loadGame = (ImageButton) findViewById(R.id.loadButton);
    loadGame.setEnabled(databaseAccess.checkForTables());
    loadGame.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            databaseAccess.loadPlayer();
            databaseAccess.loadItems();
            databaseAccess.dropTables();

        }
    });

So if checkForTables gets a rowcount of != 0 it will return true and therefore enable the Button, or disable it if rowcount = 0

Amusingly, although the tables are empty, checkForTables() returns true because getCount() seems to return a != 0 value – I just don’t get it.

  • 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-05-26T00:19:48+00:00Added an answer on May 26, 2026 at 12:19 am

    Perform a query such as select count(*) from itemtable. This query will yield you a single integer result, containing the number of rows in that table.

    For example:

    Cursor cursor = db.rawQuery("SELECT count(*) FROM itemtable");
    if (cursor.getInt(0) > 0) ... // there are rows in the table
    

    ————————————————————————————-

    Please note that the following edit was attempted by @PareshDudhat but was rejected by reviewers. I have not kept up with Android since this answer was posted, but a very brief bit of research suggests the edit (at least the change to how rawQuery() is called, I didn’t inspect the moveToFirst() but @k2col’s comment suggests it is required now as well) has merit.

    Cursor cursor = db.rawQuery("SELECT count(*) FROM itemtable",null);
    cursor.moveToFirst();
    if (cursor.getInt(0) > 0) ... // there are rows in the table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.