Trying to find an elegant solution to this common problem.
I use a map to save and retrieve program settings.
It works fairly well in most cases but a difficulty arises when the map returns a null setting.
If mapSettings.Get(i) returns null, Java cannot convert a null into a boolean and crashes.
There is no function (that I am aware of) to test if a variable is boolean (like there is IsNumber() for instance)
so the ugly solution is to put this in a Try/Catch block.
I personally do not find that very elegant, one reason being the large red dump into the log when running the program in debug mode. Try/Catch is very convenient for many potentially unforeseen circumstances but I should be able to determine if a variable is of type Boolean or not without Try/Catch.
Open to any suggestion/best practice.
Thank you
I use a map to save and retrieve program settings.
It works fairly well in most cases but a difficulty arises when the map returns a null setting.
B4X:
Dim b as Boolean
b = mapSettings.Get(i)
There is no function (that I am aware of) to test if a variable is boolean (like there is IsNumber() for instance)
so the ugly solution is to put this in a Try/Catch block.
B4X:
Dim b as Boolean
Try
b = mapSettings.Get(i)
Catch
b = False
End Try
Open to any suggestion/best practice.
Thank you