tags:

views:

201

answers:

1

Hello. I have just begun working with the Android SDK and I am having problems with my first app. Currently, I am trying to list all of the users in a big list. However, no matter what I try, the app continues to force close. I found the code in the sample files, but this is still giving me issues. Below is the code I am using.

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String[] projection = new String[] {
                People._ID,
                People._COUNT,
                People.NAME,
                People.NUMBER
             };

     //Get the base URI for the People table in the Contacts content provider.
     Uri contacts =  People.CONTENT_URI;

     //Make the query. 
     Cursor managedCursor = managedQuery(contacts,
                 projection, // Which columns to return 
                 null,       // Which rows to return (all rows)
                 null,       // Selection arguments (none)
                 // Put the results in ascending order by name
                 People.NAME + " ASC");     

        Cursor c = getContentResolver().query(Contacts.CONTENT_URI, null, null, null, null);
        startManagingCursor(c);

        String[] columns = new String[] {People.NAME};
        int[] names = new int[] {R.id.text1};

        SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, 
          R.layout.main, c, columns, names);
        setListAdapter(mAdapter);
    }

This is directly from the sample file, yet it still errors out. I have found that the line that causes the problem is the "Cursor managedCursor = managedQuery(contacts," line. Has anyone else out there seen this? I am at a loss and have not found any solutions after 2 hours or research.

Also, I have added the following line to my app's manifest file:

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>

Thanks, and if you need more information please let me know.

+3  A: 

I believe the example from the SDK docs is out of date. Try getting rid of the People._COUNT column from the cursor projection.

It's probably causing an IllegalArgumentException (see the output from adb logcat)

Alnitak
That did it. Thanks!
Josh