Hi,
I am trying to use a 'Type' and then have a map in that type.
Then I am trying to add an email to the emails map like:
When I run this I get an error:
I can't work out how to use a map in a type.
Should I be able to use a map in the type, or am I doing something wrong ?
I am trying to use a 'Type' and then have a map in that type.
B4X:
Dim Customers As Map
Type Customer (Account As String, emails As Map)
Then I am trying to add an email to the emails map like:
B4X:
Customers.Initialize
Dim account As String = "ABC123"
Dim email_account As String = "test@test.com"
If Customers.ContainsKey(account) Then
Dim c As Customer = Customers.Get(email_account)
c.emails.Put(email_account,email_account)
Else
Dim c As Customer
c.emails.Put(account,account) ' this is line 53
Customers.Put(account,c)
End If
When I run this I get an error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 53 (Main)
java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.main(main.java:29)
I can't work out how to use a map in a type.
Should I be able to use a map in the type, or am I doing something wrong ?