I want to display the phone numbers of the contacts. If I run my code in the emulator nothing happens, but when i run it in my SmartPhone I found this error in the logcat ---->
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
the code i m working with is
Cursor peopleCursor =
getContentResolver().query(ContactsContract.Contacts.CONTENT_URI
,null, null,null, null);
String [] nb = new String[peopleCursor.getCount()];
String [] Tname = new String[peopleCursor.getCount()];
if(peopleCursor.getCount()>0){
peopleCursor.moveToFirst();
Cursor numberCursor;
for(int i=0;i<peopleCursor.getCount();i++)
{
//get number
numberCursor=
getContentResolver().query(ContactsContract.
CommonDataKinds.Phone.CONTENT_URI, new String[]
{ContactsContract.CommonDataKinds.Phone.NUMBER}
,ContactsContract.CommonDataKinds.Phone._ID+"="+peopleCursor
.getString(peopleCursor.getColumnIndex(ContactsContract.Contacts._ID))
, null,null);
numberCursor.moveToFirst();
String number=numberCursor.getString(numberCursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
nb[i]=number;
//get name
String name=peopleCursor.getString(numberCursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Tname[i]=name;
peopleCursor.moveToNext();
}
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.contact_entry, peopleCursor,nb
, new int[] {R.id.checkBox});
lv.setAdapter(adapter);
}
}
any solutions please?