public class ContactsActivity extends Activity {
private TelephonyManager cTelephonyManager;
private String strSim;
private ListView contacts_lv;
private TextView contacts_item_id;
private TextView contacts_item_surname;
private TextView contacts_item_number;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts);
contacts_lv = (ListView) this.findViewById(R.id.contacts_lv);
getSimState();
// showContacts();
contacts_lv = (ListView) this.findViewById(R.id.contacts_lv);
Uri uri = Uri.parse("content://icc/adn");
String[] projection = { "_id", "name", "number" };
Cursor cur = getContentResolver().query(uri, projection, null, null,
null);
SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
R.layout.contacts_item, cur, projection, new int[] {
R.id.contacts_item_id, R.id.contacts_item_surname,
R.id.contacts_item_number });
contacts_lv.setAdapter(sca);
}
}
原来的时候还是可以查的,我现在activity就只写那么多来测试,也照样包空指针异常,
log显示 Cursor cur = getContentResolver().query(uri, projection, null, null, 这行空指针,我检查了uri对的,projection也对的,都不知道错在哪了。
------解决方案--------------------
我运行了
- Java code
Uri uri = Uri.parse("content://icc/adn");String[] projection = { "_id", "name", "number" };Cursor cur = getContentResolver().query(uri, projection, null, null,null);