0

I am using this code to search for a contact

 String[] projection = new String[]
                {
                        Contacts.People.NAME,
                        Contacts.People.NUMBER
                };

        Cursor c = this.getContentResolver().query(Contacts.People.CONTENT_URI, projection, null, null, Contacts.People.NAME + " ASC");
        c.moveToFirst();

        int nameCol = c.getColumnIndex(Contacts.People.NAME);
        int numCol = c.getColumnIndex(Contacts.People.NUMBER);

        int nContacts = c.getCount();
        String result ="";

        do
        {
            String name = c.getString(nameCol);
            String number = c.getString(numCol);
            if (name.equals("XXXX")){
                result= number;
            }
        } while(c.moveToNext());

but I am getting a nullPointerExeception on name.equals("XXXX") what would be the problem

hash-set
  • 186
  • 1
  • 12

1 Answers1

0

Seems like you are using deprecated Contacts class. It is better to use latest APIs. May be this link can help you.

Community
  • 1
  • 1
Suhas
  • 1,451
  • 14
  • 22