views:

52

answers:

1

So far I have this code from examples I have seen on here:

public class testLayout extends Activity {
final int PICK_CONTACT = 0;
ImageView image = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    image=(ImageView)findViewById(R.id.icon);
    image.setOnClickListener(onChangePerson);
}

private View.OnClickListener onChangePerson=new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);

}
};

@Override
 public void onActivityResult(int reqCode, int resultCode, Intent data) {
 super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {
 case (PICK_CONTACT) :
   if (resultCode == Activity.RESULT_OK) {
     Uri contactData = data.getData();
     Cursor c =  managedQuery(contactData, null, null, null, null);
     if (c.moveToFirst()) 
     {
       String name = c.getString(c.getColumnIndexOrThrow(People.NAME));

     }
   }
   break;
   }
   }
   }

This allows me to open up an activity that correctly shows the contacts on the phone, and let's me choose a contact. However, everytime I click on a contact, the program crashes. Any ideas why this is happening? Thanks

A: 

Ok so, thank you Hamy for pointing out to me logcat, which I previously had no knowledge of.

It turns out that I was seeing over and over "requires permission READ_CONTACTS" which I had in my android manifest file. Unfortunately, it seems I had it inside of the application tag, which was causing the program to crash without telling me why. Thank you for helping me solve this!

steve