tags:

views:

60

answers:

2

The full exception I get is:

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)

The code I used is:

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();
    }
}

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?

A: 

Split the line ContactsProvider2.java:3069 into several which only contain a single dot. That way, the line number will match a single field dereference which will tell you directly which field is null.

Aaron Digulla
Unfortunately that is inbuilt in the Android SDK system and I have no access to those.
Pentium10
Search your SDK for the source of this file and check the code.
Aaron Digulla
As stated in the question this happens only on the phone, I don't have access to those files on the phone. Ognian told that it might be a device specific bug.
Pentium10
Try to open a bug report with the device manufacturer. Since the device shows line numbers, you can also try to download the class file and decompile it.
Aaron Digulla
A: 

Add a breakpoint to exception NullPointerException and debug the code

nanda
I've already tried that, but something happens internally in the content provider(that I have no access to it) and all I see is the exception I posted.
Pentium10