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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:04:23+00:00 2026-05-31T14:04:23+00:00

I am trying to make a query to sqlite android to see for example

  • 0

I am trying to make a query to sqlite android to see for example how many users of a given username exist in a table.
This is my function. I must specify that “getContentResolver() != null” and so is variable name.

private int findSelectedUser(String name) {
        int count = 0;

        try {
            String[] whereArgs = new String[] {name};
            String[] PROJECTION = new String[] { MyProvider.SETTINGS_USERNAME };
            Cursor c = getContentResolver().query(MyProvider.SETTINGS_URI,
                    PROJECTION, MyProvider.SETTINGS_USERNAME , whereArgs, null);
            if (c != null) {
                count = c.getCount();
                c.close();
            }
        } catch (NullPointerException e) {

        }
        System.out.println("Found something? " + count);
        return count;
    }

And after running i receive the error from the subject…and don’t get it. In my where clause i have one column, in my where arguments one value.
Please help me make some sence of this, Thank you.

  • 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-31T14:04:24+00:00Added an answer on May 31, 2026 at 2:04 pm

    I guess that works:

    String[] whereArgs = new String[] {name};
    String[] PROJECTION = new String[] { MyProvider.SETTINGS_USERNAME };
    Cursor c = getContentResolver().query(MyProvider.SETTINGS_URI,
            PROJECTION, MyProvider.SETTINGS_USERNAME + "=?" , whereArgs, null);
    if (c != null) {
        count = c.getCount();
        c.close();
    }
    

    If you want to use whereArgs you have to have the same amount of ? in the where as you have items whereArgs

    whereArgs will replace the ? in the final database query

    String where = "name = ? OR name = ?";
    String[] whereArgs = new String[] {
        "Peter",
        "Jim"
    };
    

    that results in name = 'Peter' OR name = 'Jim' for the query.

    Btw: don’t catch(NullPointerException e) – make your code safe so they can’t happen

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

Sidebar

Related Questions

I'm trying to make a query that looks at a single table to see
I'm trying to make a query, something like this: SELECT * FROM table WHERE
I'm trying to make a query in HQL that see if the id of
I'm trying to make a query function that accepts two datetime.date object(start_date and end_date),
I'm trying to make a query that would do something like this... id |
I am trying to make a query string $sql = 'select * from table
I'm trying to make this query work, in my model Workshop I have a
I am trying to make a query as usual but this time I need
I'm trying to make query in a table that has a column named First
I am trying to make this query work: SELECT Stock.*, StockFeatures.Features, StockDescriptions.Detailed, StockDescriptions.Technical, PRD1.RuleValue

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.