how to get the number through a name in contacts not working for multi word strings
<p>i have tried the links 
<a href="http://stackoverflow.com/questions/8050504/how-to-get-contact-name-through-phone-number">this one</a></p>

<p>but still i am getting errors and working weirdly. i am posting my code, so please help me.
i am confused about the parameters to pass in the query.</p>

<p>i am using the following method </p>

<pre><code>void get_Number(String name)

    {

        //String name = "Daddy";

        String number = null;
            String args[]= {name};


        ContentResolver cr = getContentResolver();

        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                "DISPLAY_NAME = ?", args, null);

        if (cursor.moveToFirst()) {

            String contactId = cursor.getString(cursor
                    .getColumnIndex(BaseColumns._ID));

            Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID
                    + " = " + contactId, null, null);
            while (phones.moveToNext()) {

                number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
                int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
                Log.v("TAG3", number);

            }
        }


the problem is in the line 
</code></pre>

<p>Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    "DISPLAY_NAME = ?", args, null);</p>

<p>The above method is working for single word strings, <strong>but not for multi word strings</strong> .
how can i modify it to work correctly for multi word names in contacts.</p>

<pre><code>the otherway i have tried is



try

        {

            ContentResolver cr = getContentResolver();

            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);

            if (cur.getCount() &gt; 0) 

            {

                while (cur.moveToNext()) 

                {

                    //String iur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));

                    String Name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) 
                    {
                        if(Name.equalsIgnoreCase(name))
                        {
                            Cursor tempc=

                            etContentResolver().query(ContactsContract.CommonDataKinds.
                             Phone.CONTENT_URI,new String[]

                             {ContactsContract.CommonDataKinds.Phone.NUMBER},
                             ContactsContract.CommonDataKinds.Phone._ID+ 
                               "="+cur.getString(cur.getColumnIndex
                             (ContactsContract.Contacts._ID)), null,null);

                          tempc.moveToFirst();

                        //retrieve the phone number

                        number = 
                               tempc.getString(cur.getColumnIndex
                               (ContactsContract.PhoneLookup.NUMBER)); 



                        }
                    }
                }
            }
        }
        catch (Exception e) 
        {
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }

        if(number!=null)
            txt.append(number + "\n");
       else
        txt.append("No name");
</code></pre>

<p>the problem is with the code nested  in <code>if(Name.equalsIgnoreCase(name))</code> clause.
i have tried various ways to retrieve the number from the cursor variable, but it is throwing me an error. so please show me the correct way to retrieve the number if there is a name match for contact. thanks in advance.</p>

<p>Somebody please help i am trying it for past 2 days...</p>

<p>and this is the output of the logcat</p>

<p>02-29 16:56:04.458: E/CursorWindow(1197): Bad request for field slot 0,-1. numRows = 1, numColumns = 1</p>
