public class MainActivity extends AppCompatActivity {
private TextView et1,et2,et3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(TextView)findViewById(R.id.id);
et2=(TextView)findViewById(R.id.displayname);
et3=(TextView)findViewById(R.id.number);
ContentResolver cr=getContentResolver();
/*
查询:
1.要查询的URI,2.查询的字段3.4.查询的条件5.排序
*/
Cursor c=cr.query(Contacts.CONTENT_URI,new String[]{Contacts._ID,Contacts.DISPLAY_NAME},null,null,null);
if(c!=null)
{
while(c.moveToNext())
{
int id=c.getInt(c.getColumnIndex("Contacts._ID"));
et1.setText(""+id);
String name=c.getString(c.getColumnIndex("Contacts.DISPLAY_NAME"));
et2.setText(name);
Cursor c1=cr.query(Phone.CONTENT_URI,new String[]{Phone.NUMBER,Phone.TYPE},Phone.CONTACT_ID+"="+id,null,null);
if(c1!=null)
{
while (c1.moveToNext()) {
int type = c1.getInt(c1.getColumnIndex("Phone.TYPE"));
if (type == Phone.TYPE_HOME) {
String number = c1.getString(c1.getColumnIndex("Phone.NUMBER"));
et3.setText("家庭"+number);
}
if (type == Phone.TYPE_MOBILE) {
String number = c1.getString(c1.getColumnIndex("Phone.NUMBER"));
et3.setText("手机"+number);
}
}
c1.close();
}
}
c.close();
}
}
}
把C1有关的代码删除后就可以运行了,,求看错误