Hey folks,
I'm rather new to both Java programming and to Android development, so my learning curve is rather steep at the moment. I seem to be stuck on something that I can't find decent examples for how to work past it.
I wrote a function that gets all my phone's contacts based on examples and docs I found here & there online. The problem I cannot seem to work through is this. The following code works just fine;
private void fillData() {
// This goes and gets all the contacts
// TODO: Find a way to filter this only on contacts that have mobile numbers
cursor = getContentResolver().query(Contacts.CONTENT_URI, null, null, null, null);
final ArrayList<String> contacts = new ArrayList<String>();
// Let's set our local variable to a reference to our listview control
// in the view.
lvContacts = (ListView) findViewById(R.id.lvContacts);
while(cursor.moveToNext()) {
contacts.add(cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)));
}
// Make the array adapter for the listview.
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
contacts);
// Let's sort our resulting data alphabetically.
aa.sort(new Comparator<String>() {
public int compare(String object1, String object2) {
return object1.compareTo(object2);
};
});
// Give the list of contacts over to the list view now.
lvContacts.setAdapter(aa);
}
I want to alter the query statement by filtering out all contacts that do not have a mobile phone number entry. I attempted something like this;
cursor = getContentResolver().query(Contacts.CONTENT_URI,
new String[] {Data._ID, Phone.TYPE, Phone.LABEL},
null, null, null);
But when I do that it throws a NullPointer exception error. What's wrong with this? I got that from an example on android's site, but they had a where clause that didn't apply to my needs, so I change the where stuff to null. Is that what's screwing this up?
Thanks.