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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:06:30+00:00 2026-06-17T19:06:30+00:00

database returns a null, despite there being records in the database private static final

  • 0

database returns a null, despite there being records in the database

     private static final String DATABASE_NAME="PlayGamesdb";
     private static final String DATABASE_TABLE="peopleTable";

   public int fetchPlacesCount() {
        int count = 0;
        //String[] columns = new String[] {KEY_ROWID, KEY_NAME, KEY_HITS };
        Cursor c = ourDatabase.rawQuery("SELECT COUNT(*) from DATABASE_TABLE", null);
        c.moveToFirst();
        count = c.getInt(0);    
        return count;
    }

any ideas on what is wrong?

01-24 19:30:23.050: E/AndroidRuntime(1761): FATAL EXCEPTION: main
01-24 19:30:23.050: E/AndroidRuntime(1761): java.lang.NullPointerException
01-24 19:30:23.050: E/AndroidRuntime(1761):     at com.example.dbsample.PlayGame.fetchPlacesCount(PlayGame.java:93)
01-24 19:30:23.050: E/AndroidRuntime(1761):     at com.example.dbsample.SQLiteExample.onClick(SQLiteExample.java:123)
01-24 19:30:23.050: E/AndroidRuntime(1761):     at android.view.View.performClick(View.java:3511)

here is the onclick that in the other class used to call the fetchPlacesCount method

 case R.id.bSQLnumberofrows:
        int x = 0;
        PlayGame ec = new PlayGame(this);
        ec.open();
        x = ec.fetchPlacesCount();
        ec.close();
        sqlRow.setText(x);
        break;

EDIT:

after fixing the problems the code below is now working and shows the correct number of rows as a Toast message, so now one problem fixed and one more to go, still error with the setText method for putting the number in the EditText. that is what I will work on next, to see what is wrong with this textView.

using the Toast message was a good way to find out that the method was returning the correct number.

public int fetchPlacesCount() {
        int count = 0;
        Cursor q = ourDatabase.rawQuery("SELECT COUNT(*) from " + DATABASE_TABLE, null);
        q.moveToFirst();
       count = q.getInt(0);
        return count;
    }

int the other class

    case R.id.bSQLnumberofrows:
        PlayGame ec = new PlayGame(this);
        ec.open();
        int x = ec.fetchPlacesCount();
        ec.close();
      //  sqlRow.setText(x);
        Toast.makeText(SQLiteExample.this, "value of x " + x , Toast.LENGTH_SHORT).show();
        break;
  • 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-17T19:06:31+00:00Added an answer on June 17, 2026 at 7:06 pm

    I think you should return the cont variable instead of count as you are not assigning any value to count variable.

    int cont = c.getInt(0); 
        return cont;
    

    EDITED:

    Fire your query as below:

    Cursor c = ourDatabase.rawQuery(“SELECT COUNT(*) from ” + DATABASE_TABLE, null);

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

Sidebar

Related Questions

SQL select command SELECT a.RDB$CHARACTER_SET_NAME FROM RDB$DATABASE a returns NULL. What character set is
the call em.find(Department.class, D1) returns null even when D1 exists in database. the debug
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is
my c# program selects a datetime field from database and returns the data like
Suppose you want to get a record from database which returns a large amount
I use kohana and when you try to fetch data from database it returns
I have a stored procedure called WEB_SEL_SECURITY_QUESTIONS in my sql database which returns a
load() just returns a proxy by default and database won’t be hit until the
I have a dataset that returns questions and answers from the database, each answer
The code below returns the 10 most recent entries to a MySQL database. That's

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.