Android Question Error with Map object within a Type structure

Indy

Active Member
Licensed User
Longtime User
Hi

I have declared an variable of type Map within a Type structure;

B4X:
Type Request(WebRequest as String, WebParams As Map)

Dim UserRequest as Request

Request.WebRequest = "Test"
Request.WebParams.Initialize

The issue I'm having is on the 2nd line - the Initialize. I get an error;

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.collections.Map.Initialize()' on a null object reference

I'm obviously doing something wrong but, not sure what. Is that kind of declaration even permitted?

Thanks
 

JordiCP

Expert
Licensed User
Longtime User
Try with
B4X:
Type Request(WebRequest as String, WebParams As Map)

Dim UserRequest as Request
UserRequest.initialize                      'init the variable instance
UserRequest.WebRequest = "Test"
UserRequest.WebParams.Initialize    'init the field of the variable instance
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi JordiCP

Perfect! That was it! I didn't initialise the object UserRequest.

Thank you very much.
 
Upvote 0
Top