Android Question MAP "Null" Value Assignment Generates Java NullPointerException

DaveB4A

Member
Licensed User
Longtime User
I have a MAP defined which contains multiple STRING entries. Most of them contain text - but some are "blank" - meaning they are "NULL".

When I attempt to load those entries into an EditText view, any MAP entry that is "NULL" generates a Java NullPointerException and the application terminates. However, if the MAP entry contains actual text, the assignment works fine.

For example, the following code will fail if "firstname" is NULL.

B4X:
EditText1.Text = Contacts.Chosen_Contact_Field_Map.Get("firstname")


In order to circumvent the issue, I found that if I assign each MAP field to a STRING variable and then assign the EditText view to the STRING variable, all entries work fine - even the "NULL" entries.

For example, the following code works as desired, even when "firstname" is NULL.

B4X:
Dim Chosen_Contact_FirstName As String
Chosen_Contact_FirstName = Contacts.Chosen_Contact_Field_Map.Get("firstname")
EditText1.Text = Chosen_Contact_FirstName

Could someone please point me in the direction of where in the documentation this behavior is explained. I'm sure it's due to some kind of "conversion", perhaps... But I really don't understand why my "workaround" actually works.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…