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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:24:53+00:00 2026-05-19T04:24:53+00:00

my code is as following String projection[] = new String[]{ ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; Cursor

  • 0

my code is as following

String projection[] = new String[]{ ContactsContract.Contacts._ID,
                                            ContactsContract.Contacts.DISPLAY_NAME };
        Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, //The URI, using the content:// scheme, for the content to retrieve.
                        projection,             // projection
                        null,               // selection
                        null,               // selectionArgs
                        ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");

I want to add contact id, name and number (MAIN or any one of type) to intent, but problem is that I am unable to access Name. And another problem is that for each contact id returns “-1”. why?
Is there any solution?

  • 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-19T04:24:54+00:00Added an answer on May 19, 2026 at 4:24 am

    Instead off supplying the value of projection variable as null in the query method you should try it like this:

    String[] projection = new String[] {ContactsContract.Data._ID,
                                        ContactsContract.Data.CONTACT_ID,
                                        ContactsContract.Data.DISPLAY_NAME};
    

    It is clearly written in Android Developer Documentation that:

    Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named “_id” or this class will not work.

    See here in the documentation:

    http://developer.android.com/reference/android/widget/CursorAdapter.html

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

Sidebar

Related Questions

I have following code in pre-Android2.0 API: String[] PROJECTION = new String[] { Contacts.People._ID,
I have the following code. int phoneContactID = new Random().nextInt(); Cursor contactLookupCursor = context.getContentResolver().query(
Cursor cursor = resolver.query( Data.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] {String.valueOf(rawContactId)}, null); With PROJECTION being:
I can load a list with the following code String[] projection = new String[]
I have the following code: m_curContacts = managedQuery(uri, projection, selection, selectionArgs, sortOrder); String[] fields
i am using the following code String keyword=request.getParameter(keyword); keyword = keyword.toLowerCase(); keyword.replaceAll( , );
Got the following production code below, I'm using it for a new driver. portName
Given the following code: string source = Some Unicode String; foreach( char value in
I have the following code: String website = http://www.somewebsite.com/; Document doc = Jsoup.connect(website).get(); Elements
I have the following code string three() { return three; } void mutate(string& ref)

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.