Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid getContentResolver().query error
    primarykey
    data
    text
    <p>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.</p> <p>I wrote a function that gets all my phone's contacts based on examples and docs I found here &amp; there online. The problem I cannot seem to work through is this. The following code works just fine;</p> <pre><code> 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&lt;String&gt; contacts = new ArrayList&lt;String&gt;(); // 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&lt;String&gt; aa; aa = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_multiple_choice, contacts); // Let's sort our resulting data alphabetically. aa.sort(new Comparator&lt;String&gt;() { 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); } </code></pre> <p>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;</p> <pre><code> cursor = getContentResolver().query(Contacts.CONTENT_URI, new String[] {Data._ID, Phone.TYPE, Phone.LABEL}, null, null, null); </code></pre> <p>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?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload