Android Question NPE Error (Map.Initialize)

amiria703

Member
Hello Everyone
I made an app with b4a and I tested it with a phone with android 5.1, Now I tested my app with another device using Android 7.1.1.
The previous test was successful but with android 7 I get NPE (NullPointException) Error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftwhere.b4a.objects.collections.Map.Initialize()' on a null object reference.
I wanted to know what happened so I saw this part of Error:
'…Map.Initialize()'
In Process globals I defined a Map
And then initialized that in Activity Create sub
Later, I used that map in another sub.
How to fix this problem?
 

amiria703

Member
Logs:
  1. Logger connected to: Sony E6633
  2. --------- beginning of crash
  3. --------- beginning of main
  4. *** Service (starter) Create ***
  5. ** Service (starter) Start **
  6. ** Activity (main) Create, isFirst = true **
  7. ** Activity (main) Resume **
  8. ** Activity (main) Pause, UserClosed = false **
  9. ** Activity (newcontact) Create, isFirst = true **
  10. java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.collections.Map.Initialize()' on a null object reference

Some parts of code:
B4X:
Sub Process_Globals
        'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim contact As Map
      
End Sub
...
Sub Activity_Create(FirstTime As Boolean)
        'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        contact.Initialize
        ...
End Sub
...
Sub okID_Click
        ...
        NewIDAdded
    ...
End Sub
...
Sub NewIDAdded
        ...
    contact.Put(WhichSocialNetwork,ID)
        ...
End Sub
...
Sub Done_Click
        ...
        Main.Infos.Put(EditText1.Text,contact)
        Activity.Finish
        ...
End Sub
...
 
Upvote 0
Top