title: How to display all the phone contacts (name, phone number) in a textView or String?
body: <pre><code>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());
      }
  }
  </code></pre>
  
  <p>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...</p>
  
  <pre><code>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
  </code></pre>