0

i want to select and display a particular contact on the button click in list,button is named Add and on click the function onContactClick is to be called,so that when i click the button my phone contact get displayed and i can select the contact and display it in list view.i am doing the following

ArrayList<Econtacts> econtacts;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third);
    etext=(EditText)findViewById(R.id.emtext);
   econtacts = new ArrayList<>();
   Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
            null, null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            id = cur.getString(
                    cur.getColumnIndex(ContactsContract.Contacts._ID));
            name = cur.getString(
                    cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                phone = Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));          //Query phone here.  Covered next
            }

            econtacts.add(new Econtacts(phone, name, id));

        }
    }
    public void onContactsClick (View  view) {
    ArrayAdapter<Econtacts> adapter =new ArrayAdapter<Econtacts>(getApplicationContext(),R.layout.text,econtacts);
    list = (ListView) findViewById(R.id.contactList);
    list.setAdapter(adapter);
}

and the Econtacts class is here

public class Econtacts {
private String _id;
private int _econtacts;
private String _ename;

public int get_econtacts() {
    return _econtacts;
}

public String get_id() {
    return _id;
}

public void set_id(String _id) {
    this._id = _id;
}

public void set_econtacts(int _econtacts) {
    this._econtacts = _econtacts;
}

public String get_ename() {
    return _ename;
}

public void set_ename(String _ename) {
    this._ename = _ename;
}

public Econtacts(int _econtacts,String _ename,String _id) {

    this._econtacts = _econtacts;
    this._ename=_ename;
    this._id=_id;} }

Am i doing something wrong because whenever i click the add button the message that application has stopped comes.Please can anybody guide me.Thanks in advance

Isha
  • 11
  • 6
  • We can't help you without the error logs. – OneCricketeer Mar 10 '16 at 17:50
  • Please refer to [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this), and then [edit your question](http://stackoverflow.com/posts/35923273/edit) – OneCricketeer Mar 10 '16 at 17:53
  • @ cricket_007 thanks i will add logcat in few minutes – Isha Mar 10 '16 at 17:59

0 Answers0