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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:16:18+00:00 2026-06-02T11:16:18+00:00

I m trying to read the contacts from the contacts table and store all

  • 0

I m trying to read the contacts from the contacts table and store all of them into a list variable..but not able to make out why it doesnt seem to work..gets a force close on execution.the contacts are needed to be send over a json object to a web server.

      private static final String TABLE_CONTACTS = "contacts";



// contacts JSONArray
JSONArray contacts = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    List<contact> l=new ArrayList<contact>();
    String query="SELECT * FROM"+ TABLE_CONTACTS;

     DBHelper help= new DBHelper(getBaseContext()); 
    SQLiteDatabase db=help.getWritableDatabase();
    Cursor cursor = db.rawQuery(query, null);
    if(cursor.moveToFirst())
    {
        do{
            contact contact = new contact();
            contact.setID(Integer.parseInt(cursor.getString(0)));
            contact.setName(cursor.getString(1));
            contact.setPhoneNumber(cursor.getString(2));
            Toast.makeText(this,contact.name,Toast.LENGTH_LONG);
             l.add(contact);
        }
        while(cursor.moveToNext());
    }

and manifest file has 2 permissions

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.READ_CONTACTS"/>

and DBHelper class which is used to extend sqlitopenhelper to getWritableDatabase..

    class DBHelper extends SQLiteOpenHelper { 
private static final String DATABASE_NAME = "contactsManager";

   // Contacts table name
   private static final String TABLE_CONTACTS = "contacts";
DBHelper(Context context) { 
    super(context,DATABASE_NAME, null,1); 
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub      
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub      
}

}

  • 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-02T11:16:20+00:00Added an answer on June 2, 2026 at 11:16 am
    private void getDetails(){
        Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
        String[] projection    = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                            ContactsContract.CommonDataKinds.Phone.NUMBER };
        Cursor names = getContentResolver().query(uri, projection, null, null, null);
        int indexName = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
        int indexNumber = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
        names.moveToFirst();
        do {
           String name   = names.getString(indexName);
           Log.e("Name new:", name);
           String number = names.getString(indexNumber);
           Log.e("Number new:","::"+number);
        } while (names.moveToNext());
    }
    

    use the above code to get a list of name and numbers from contacts database.

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

Sidebar

Related Questions

I 'm trying to read and display contacts from phone book in android. My
i'm trying to read contacts with this code but it only gets Contacts but
I am trying to read data from an excel sheet but there is an
I am trying to read Contact names, phone #'s, and emails from the ContactsContract
Trying to read an RSS and select information using Linq but can't seem to
Im trying to read a column of String values from my DB. Im trying
I'm trying to read the event log for a security audit for all users
I'm trying to read the cocos2d api doc but I'm confused about what the
I read various post's prior to this. but none of them seemed to work
I'm currently trying to learn Django from the book and I read most of

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.