LucaMs Expert Licensed User Longtime User Feb 1, 2022 #1 I found that CreateMap accepts Null values as well, like so: B4X: MyMap = CreateMap("Value":Null) but If I had something like: B4X: MyMap = Create(Null) Private Sub Create(Value As Map) As Map Return CreateMap("Value":Value) End Sub I would get an error: java.lang.RuntimeException: Object should first be initialized (Map) <--- Map Value, the parameter. Obviously I got around this problem easily but I wonder if it is right for this to happen. Last edited: Feb 1, 2022
I found that CreateMap accepts Null values as well, like so: B4X: MyMap = CreateMap("Value":Null) but If I had something like: B4X: MyMap = Create(Null) Private Sub Create(Value As Map) As Map Return CreateMap("Value":Value) End Sub I would get an error: java.lang.RuntimeException: Object should first be initialized (Map) <--- Map Value, the parameter. Obviously I got around this problem easily but I wonder if it is right for this to happen.
FrostCodes Active Member Licensed User Longtime User Feb 1, 2022 #2 Your Sub is accepting a Map value not an object so that's why it's crashing. Null is not a Map. Upvote 1
Erel B4X founder Staff member Licensed User Longtime User Feb 1, 2022 #3 Change the type of Value to Object. Upvote 0
LucaMs Expert Licensed User Longtime User Feb 1, 2022 #4 FrostCodes said: Your Sub is accepting a Map value not an object so that's why it's crashing. Null is not a Map. Click to expand... That's not the problem, it's creating the Map that way. You could have: B4X: MyMap = Create2(Null) Log(MyMap)'ignore Private Sub Create2(Value As Map) As Map Return Value End Sub without getting errors. Erel said: Change the type of Value to Object. Click to expand... LucaMs said: Obviously I got around this problem easily but I wonder if it is right for this to happen. Click to expand... Upvote 0
FrostCodes said: Your Sub is accepting a Map value not an object so that's why it's crashing. Null is not a Map. Click to expand... That's not the problem, it's creating the Map that way. You could have: B4X: MyMap = Create2(Null) Log(MyMap)'ignore Private Sub Create2(Value As Map) As Map Return Value End Sub without getting errors. Erel said: Change the type of Value to Object. Click to expand... LucaMs said: Obviously I got around this problem easily but I wonder if it is right for this to happen. Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Feb 1, 2022 #5 > but I wonder if it is right for this to happen. Yes. The "value" map is uninitialized. You cannot do anything with an uninitialized map, except of initialize it. Upvote 0
> but I wonder if it is right for this to happen. Yes. The "value" map is uninitialized. You cannot do anything with an uninitialized map, except of initialize it.
LucaMs Expert Licensed User Longtime User Feb 1, 2022 #6 Erel said: Change the type of Value to Object. Click to expand... LucaMs said: Obviously I got around this problem easily . Click to expand... Setting the parameter type to Object is not a good choice; the developer needs to know what kind of data to pass. More correctly I check that the past Map is initialized depending on whether it is or not... B4X: Private Sub Create(Value As Map) As Map If Value.IsInitialized Then Return CreateMap("Value":Value) Else Return CreateMap("Value":Null) End If End Sub Upvote 0
Erel said: Change the type of Value to Object. Click to expand... LucaMs said: Obviously I got around this problem easily . Click to expand... Setting the parameter type to Object is not a good choice; the developer needs to know what kind of data to pass. More correctly I check that the past Map is initialized depending on whether it is or not... B4X: Private Sub Create(Value As Map) As Map If Value.IsInitialized Then Return CreateMap("Value":Value) Else Return CreateMap("Value":Null) End If End Sub
LucaMs Expert Licensed User Longtime User Feb 1, 2022 #7 Erel said: Yes. The "value" map is uninitialized. You cannot do anything with an uninitialized map, Click to expand... ? Upvote 0
Erel said: Yes. The "value" map is uninitialized. You cannot do anything with an uninitialized map, Click to expand... ?
LucaMs Expert Licensed User Longtime User Feb 1, 2022 #8 Yes, now it is clearer to me; in fact, an uninitialized object is not "yet" null. Upvote 0
LucaMs Expert Licensed User Longtime User Feb 1, 2022 #9 LucaMs said: Yes, now it is clearer to me; in fact, an uninitialized object is not "yet" null. Click to expand... No, not so much (at all, I would say ?) because even the code at post #4 should throw an exception, then. Upvote 0
LucaMs said: Yes, now it is clearer to me; in fact, an uninitialized object is not "yet" null. Click to expand... No, not so much (at all, I would say ?) because even the code at post #4 should throw an exception, then.