title: ContactsContract.PhoneLookup.NUMBER makes ContentResolver query crash
body: <p>I am trying to send an implicit intent to my contacts app for the user to select a contact. My app will then extract that contact's name and phone number for use in the app. </p>
  
  <p>(Note: I'm on Chapter 21 of BigNerdRanch's Android book, doing the challenge so there's no answer key. I looked on their [inactive] forums and couldn't find an explanation for this bug.) </p>
  
  <p>So at first the book tutorial had it working where the query only contained the name. But when I tried to add another column for the phone number, it would crash every time I selected a contact and thus was in the process of returning to the original activity that sent the implicit intent.  </p>
  
  <p>I thought maybe it crashed because my contact I selected did not have a phone number stored with it? So I tried one with a phone number AND a name, and it still crashed. </p>
  
  <p>Here is the code, all with the same class (which extends a support fragment). Thanks for any help!</p>
  
  <p>FWIW: Here is the page where you can download the solution for chapter 21 here <a href="http://www.bignerdranch.com/we-write/android-programming" rel="nofollow">http://www.bignerdranch.com/we-write/android-programming</a> , which shows basically all the code I have except what I altered to do the challenge problem.</p>
  
  <p>onCreateView(...):</p>
  
  <pre><code>...
  mSuspectButton = (Button)v.findViewById(R.id.crime_suspectButton);
          mSuspectButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                  startActivityForResult(i, REQUEST_CONTACT);
              }
          });
          if(mCrime.getSuspect() != null) {
              mSuspectButton.setText(mCrime.getSuspect());
          }
  
          mDialButton = (Button)v.findViewById(R.id.crime_dialButton);
          if(mCrime.getPhoneNumber() == null) {
              mDialButton.setVisibility(View.INVISIBLE);
          }
          mDialButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(Intent.ACTION_DIAL, mCrime.getPhoneNumber());
              }
          });
          return v;
      }
  </code></pre>
  
  <p>onActivityResult:</p>
  
  <p>When the code is like this, it crashes.</p>
  
  <pre><code>@Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == REQUEST_CONTACT) {
          Uri contactUri = data.getData();
              //Specify which fields you want your query to return values for.
              String[] queryFields = new String[] {
  
                      ContactsContract.Contacts.DISPLAY_NAME,
                      ContactsContract.PhoneLookup.NUMBER
              };
  
              //Perform your query - the contactUri is like a "where" clause here
              Cursor c = getActivity().getContentResolver().query(contactUri, queryFields, null, null, null);
  
              //Double-check that you actually got results
              if (c.getCount() == 0) {
                  c.close();
                  return;
              }
  
              //Pull out the first column of the first row of data - that is your suspect's name.
              c.moveToFirst();
              Log.d(TAG, "" + c.getColumnCount());
              String suspect = c.getString(0);
              String phoneNumber = "1"; //c.getString(1);  
              mCrime.setSuspect(suspect);
              mCrime.setPhoneNumber(phoneNumber);
              if(mCrime.getPhoneNumber() == null) {
                  mDialButton.setVisibility(View.INVISIBLE);
              }
              mSuspectButton.setText(suspect);
  
              c.close();
  
  
          }
  </code></pre>
  
  <p>NOTE: In this line</p>
  
  <pre><code>String phoneNumber = "1"; //c.getString(1);  
  </code></pre>
  
  <p>It is supposed to be "c.getString(1)", but I was testing any number to see if it would still crash, and it still did. </p>
  
  <p>When I replace the query with this,</p>
  
  <pre><code>String[] queryFields = new String[] {
  
                      ContactsContract.Contacts.DISPLAY_NAME
              };
  </code></pre>
  
  <p>then it works just fine, and does not crash. </p>
  
  <p>LogCat:</p>
  
  <pre><code>05-19 18:38:38.462: E/AndroidRuntime(20212): FATAL EXCEPTION: main
  05-19 18:38:38.462: E/AndroidRuntime(20212): Process: com.bignerdranch.android.criminalintent, PID: 20212
  05-19 18:38:38.462: E/AndroidRuntime(20212): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65539, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/133r155-3D2F5537/155 flg=0x1 }} to activity {com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimePagerActivity}: java.lang.IllegalArgumentException: Invalid column number
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3365)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread.access$1300(ActivityThread.java:135)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.os.Handler.dispatchMessage(Handler.java:102)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.os.Looper.loop(Looper.java:136)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at java.lang.reflect.Method.invoke(Method.java:515)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at dalvik.system.NativeStart.main(Native Method)
  05-19 18:38:38.462: E/AndroidRuntime(20212): Caused by: java.lang.IllegalArgumentException: Invalid column number
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.content.ContentResolver.query(ContentResolver.java:461)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.content.ContentResolver.query(ContentResolver.java:404)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at com.bignerdranch.android.criminalintent.CrimeFragment.onActivityResult(CrimeFragment.java:618)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:166)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.Activity.dispatchActivityResult(Activity.java:5423)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
  05-19 18:38:38.462: E/AndroidRuntime(20212):    ... 11 more
  05-19 18:38:40.382: D/Lexi(20281): {"location":"provo","age":"22","name":"Lexi"}
  05-19 18:38:40.422: I/Adreno-EGL(20281): &lt;qeglDrvAPI_eglInitialize:320&gt;: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
  05-19 18:38:40.442: D/OpenGLRenderer(20281): Enabling debug mode 0
  </code></pre>