开发者

Conflict between two versions with reading contacts in android

I created an application that reads contacts from the phone and it works fine on platform version of 3.1 but it throws NullPointerException when i run it on 2.3.3 platform.Can anyone show me the reason for this error.

ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,null, null, null);
       while (cur.moveToNext()) {
            String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                           Cursor phones = cr.query(Phone.CONTENT_URI, null,
               Phone.CONTACT_ID + " = " + id, null, null);
           while (phones.moveToNext()) {
               String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
               int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
               System.out.println("Numeber= "+number);
               switch (type) {
                   case Phone.TYPE_HOME:
                       home=number;
                       break;
                   case Phone.TYPE_MOBILE:
                       mobile=number;
                       break;
                   case Phone.TYPE_WORK:
                       work=number;
                       break;                       
                   case Phone.TYPE_OTHER:
                       other=number;
                       break;

           }              

           }
           phones.close();

       }开发者_StackOverflow中文版                

thanks.


use URI "Phone.CONTENT_URI". It is being tested for 2.3.3 or 2.2.1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜