I am trying contact screen and when user pick contact from there it's name and phone number will display in Toast message in onActivityResult
screen. The problem is that when I pick the contact it's name is displaying in the toast when I am trying to display number error occurring:
java.lang.illegalStateException:Couldn't read row 0,col -1 from CursorWindow.Make sure the Cursor is initialized correctly before accessing data from it.
Here is my code of onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==Activity.RESULT_OK){
switch(requestCode){
case 1:
Cursor c=managedQuery(data.getData(), null, null, null, null);
if(c.moveToFirst()){
try{
String name=c.getString(c.getColumnIndex(People.NAME));
String no=c.getString(c.getColumnIndex(People.NUMBER));
Toast.makeText(getApplicationContext(), no, 1).show();
}
catch(Exception e){
Log.v("error", e.toString());
}
}
break;
}
}
}