How to track down which field is causing NullPointerException when inserting custom field into Contacts Data table?
<p>The full exception I get is:</p>

<pre><code>07-16 19:19:17.244: ERROR/DatabaseUtils(151): java.lang.NullPointerException
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.ContactsProvider2.insertData(ContactsProvider2.java:3069)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.ContactsProvider2.insertInTransaction(ContactsProvider2.java:2930)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.CContactsProvider2.insertInTransaction(CContactsProvider2.java:156)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.HtcContactsProvider2.insertInTransaction(HtcContactsProvider2.java:1281)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.SQLiteContentProvider.insert(SQLiteContentProvider.java:90)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at com.android.providers.contacts.ContactsProvider2.insert(ContactsProvider2.java:2737)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:150)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:170)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at android.os.Binder.execTransact(Binder.java:287)
07-16 19:19:17.244: ERROR/DatabaseUtils(151):     at dalvik.system.NativeStart.run(Native Method)
</code></pre>

<p>The code I used is:</p>

<pre><code>public void saveFormality() {
    ContentValues values = new ContentValues();
    values.put(Data.DATA1, this.getFormality() ? "1" : "0");
    saveDataWithMimeType(clsContacts.MIMETYPE_FORMALITY, values, this.getId());
}


private void saveDataWithMimeType(String mimetype, ContentValues values, String contactid) {
    try {
        int mod = ctx.getContentResolver().update(
                Data.CONTENT_URI,
                values,
                ContactsContract.Data.RAW_CONTACT_ID + "=" + contactid + " AND " + ContactsContract.Data.MIMETYPE + "= '"
                        + mimetype + "'", null);

        if (mod == 0) {
            values.put(Data.RAW_CONTACT_ID, contactid);
            values.put(Data.MIMETYPE, mimetype);
            // this is where exception occurs
            Uri u=ctx.getContentResolver().insert(Data.CONTENT_URI, values);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>

<p>This happens on the phone only, and not in the emulator. All fields were checked and none of them are nulls. What could be the cause?</p>
