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

  • Home
  • SEARCH
  • 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 8650959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:56:45+00:00 2026-06-12T13:56:45+00:00

public class ImportContactsActivity extends Activity { /** Called when the activity is first created.

  • 0
public class ImportContactsActivity extends Activity {
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact);
        TextView txt = (TextView)findViewById(R.id.con);
        String msg = "";

        ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        while (cursor.moveToNext()) {
                String name = cursor.getString(cursor.getColumnIndexOrThrow(People.NAME));
                String number = cursor.getString(cursor.getColumnIndexOrThrow(People.NUMBER));
                String email = cursor.getString(cursor.getColumnIndexOrThrow(People.PRIMARY_EMAIL_ID));

                msg += name + " " + number + " " + email + "\n";
        }
        txt.setText(msg.toString());
    }
}

I am developing an application in which the application is able to send an email containing all the current phone contacts (name + phone number) as a backup alternative. I am trying out on how to extract all the phone contacts information and display them on the TextView… But I cannot do it, someone please consult me. Thanks…

LogCat
10-09 15:22:48.634: E/AndroidRuntime(680): FATAL EXCEPTION: main
10-09 15:22:48.634: E/AndroidRuntime(680): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.example.importcontacts/com.example.importcontacts.ImportContactsActivity} : java.lang.IllegalArgumentException: column 'name' does not exist
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.os.Looper.loop(Looper.java:137)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 15:22:48.634: E/AndroidRuntime(680):  at java.lang.reflect.Method.invokeNative(Native Method)
10-09 15:22:48.634: E/AndroidRuntime(680):  at java.lang.reflect.Method.invoke(Method.java:511)
10-09 15:22:48.634: E/AndroidRuntime(680):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 15:22:48.634: E/AndroidRuntime(680):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 15:22:48.634: E/AndroidRuntime(680):  at dalvik.system.NativeStart.main(Native Method)
10-09 15:22:48.634: E/AndroidRuntime(680): Caused by: java.lang.IllegalArgumentException: column 'name' does not exist
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:267)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:78)
10-09 15:22:48.634: E/AndroidRuntime(680):  at com.example.importcontacts.ImportContactsActivity.onCreate(ImportContactsActivity.java:46)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.Activity.performCreate(Activity.java:4465)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-09 15:22:48.634: E/AndroidRuntime(680):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-09 15:22:48.634: E/AndroidRuntime(680):  ... 11 more
  • 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-12T13:56:47+00:00Added an answer on June 12, 2026 at 1:56 pm

    use ContactsContract.CommonDataKinds.Phone.CONTENT_URI instead of ContactsContract.Contacts.CONTENT_URI so that you can get the phone number, and change these lines

    String name = cursor.getString(cursor.getColumnIndexOrThrow(People.NAME));
    String number = cursor.getString(cursor.getColumnIndexOrThrow(People.NUMBER));
    String email = cursor.getString(cursor.getColumnIndexOrThrow(People.PRIMARY_EMAIL_ID));
    

    to

    String name = cursor.getString(cursor.getColumnIndexOrThrow(Phone.DISPLAY_NAME));
    String number = cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER));
    

    You will need another query to get the email_id. From the first cursor you can get the contact id like so

    long contactId = cursor.getLong(cursor.getColumnIndexOrThrow(Phone.CONTACT_ID));
    

    Now query the email uri using the contactId in your filter

    long emailId;
    Cursor cur = getContentResolver()
                        .query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                         new String[]{"_id"},
                         "contact_id = " + contactId,
                         null,null);
    if(cur != null && cur.moveToFirst()){
        emailId = cur.getLong(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class Boards : TabActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Tab);
public class check extends Activity { /** Called when the activity is first created.
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class master extends Activity { ProgressDialog progressDialog; EditText tahmini_kelime; EditText girilen_sayi ; EditText

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.