Android Question Error messages for ContactsUtils library

Eric H

Active Member
Licensed User
Longtime User
I am using the contactutils library to create contacts.

I am using a line like this to create the contact. It works perfectly on my Galaxy Nexus, Galaxy S4, my wife's Galaxy S3, all the emulator variations that I have tried (android versions 2.2 to version 4.3):
B4X:
cu.InsertContact("name" , "1234567890")

Two of my friends have HTC Rhyme phones and they both get this error when they press the button in my app that would fire off the cu.InsertContact code:
B4X:
An error has occurred in sub: contactsutils_ww3(java line:574) java.Lang.NullPointerException. Continue?

I have no idea what would be causing this, and have spent quite a few hours trying different variation of ways of doing things...

Does anyone have any idea of what could be going on here?

Also, does anyone have an HTC Rhyme that they would like to try the code on to see if things are acting the same, or to try and assist (I don't own that device).

Thanks B4A folks,
Eric H
 

Eric H

Active Member
Licensed User
Longtime User
Erel, at this point I am not sure, so I will create a new project with only the bare bones needed to create a contact and I'll have them run it and get the error so I can eliminate any other possibilities non my code. I'll post an update in a few.
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
I just had her try it again with the bare bones project and it popped the same error:
"An error has occurred in sub: contactsutils_ww3 (java line 574) java.lang.NullPointerException Continue?"

Line 574 of contactutil.java is:
B4X:
_vvvvv2.Insert(_vvvvv3,(android.content.ContentValues)(_values.getObject()));

'from ObfuscatorMap.txt
vvvvv2=cr
vvvvv3=datauri


Here is the zip folder for the bare bones project:

For reference, here is the zip, the apk, and a dump of the code I am using in the bare bones project:
B4X:
#Region  Project Attributes
    #ApplicationLabel: HTCRhymeTS
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    Dim cu As ContactsUtils
    cu.Initialize
End Sub

Sub Globals
    Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("HTCRhymeTS")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
    'contact's name starts with AA and ends with a timestamp
    'contact's phone number is "5551234567"
    cu.InsertContact("AA" & DateTime.Now, "5551234567")
End Sub
 

Attachments

  • HTCRhymeTS1.zip
    9.9 KB · Views: 223
  • HTCRhymeTS.apk
    110.7 KB · Views: 220
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
I don't know Java, but here is what I found about this error:

java.lang.NullPointerException: Overview

NullPointerException is a runtime Exception thrown by the JVM when your application code, other referenced API(s) or middleware (Weblogic, WAS, JBoss...) encounters the following conditions:

-Attempting to invoke an instance method of a null object
-Attempting to access or modify a particular field of a null object
-Attempting to obtain the length of such null object as an array
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
Thanks Erel, I will do that. I don't think that is related directly to the issue though, do you? As i recall, the real program didn't have a cu.initialize statement at all. I can double check.
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
I have had a chance to look at my code in the actual app. My code actually did include
B4X:
cu.Initialize

So, here is what else I discovered...

Both of my friends that have HTC Rhymes get the error, and my brother in law who has an HTC One gets the error. The app is actually creating contacts, but the contacts are named 'unnamed', instead of ["AA" & DateTime.Now] and do not have any phone number info.

I did some more searching and found this: http://stackoverflow.com/questions/10702489/contentresolver-query-is-throwing-a-nullpointerexception This information doesn't mean a lot to me, as I don't know Java, but it sounds like the ContentProvider/ContentResolver in HTC Sense is either bugged to not allow null values where they should be allowed, and that it can be fixed by passing non-null values instead (or something like that...?)

Maybe the ContactsUtils library is passing the ContentProvider/ContentResolver null values that it refuses to accept...? I guess I am just hoping that I am barking up the right tree, since I am not able to figure this one out on my own.

Thanks,
Eric


Oh, and Erel, do you have any devices that are running HTC Sense that you can try the ContactsUtils library with to see if you are able to use the InsertContact function?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The phone type field was missing in InsertContact.

I will update ContactsUtils with the corrected code.

B4X:
  values.Initialize
   values.PutLong("raw_contact_id", rawContactId)
   values.PutString("mimetype", "vnd.android.cursor.item/phone_v2")
   values.PutInteger("data2", 12) 'phone type main <---- this line was missing
   values.PutString("data1", Phone)
   cr.Insert(dataUri, values)
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
I am back here with another related problem, which is only happening on one of my user's devices. He has a galaxy s3 and is the only one having any issues. My app works great on all other devices, including my wife's galaxy s3 and my galaxy s4. All 3 of our devices are unrooted and running the stock ROM. I even had him email me a complete list of all the apps on his device and had him uninstall some apps that had anything to do with task/memory management, contacts, backup, etc... He sent me screenshots of my app's app-info screen so I could verify he is running the newest version. He tried uninstalling the app and reinstalling it. The screenshot shows the error he is getting:


I haven't explicitly created any URI objects in my code, is there an initialize for URI missing from the contactsutils code module in the insertcontact code?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…