Android Question Google Maps Example Works On Debug But Crashed On Direct Run

Richard Goh

Active Member
Licensed User
Longtime User
Hi, I have a very weird behavior on this Google Maps example program https://www.b4x.com/android/forum/threads/google-maps-with-fusedlocationprovider.83876/.
This example is working in debugging mode with stepping through the code. But it's will crash when I direct run without step into the code. What I suspected is that the maps loaded slower than adding the marker in Map_Ready function. Ended up it's caused the Maps not initialized. Below are the errors displayed in the logs. Any advice to overcome this problem? Thanks in advance.

I am using
B4A v8.30,
Android\platforms\android-28\android.jar,
Java\jdk1.8.0_131\bin\javac.exe

java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference
at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:197)
at com.google.android.gms.maps.MapFragment$zza$1.zza(Unknown Source:14)
at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source:47)
at android.os.Binder.transact(Binder.java:605)
at fp.b:)com.google.android.gms.dynamite_mapsdynamite@[email protected] (040408-213742215):15)
at com.google.android.gms.maps.internal.bg.a:)com.google.android.gms.dynamite_mapsdynamite@[email protected] (040408-213742215):4)
at com.google.maps.api.android.lib6.impl.bj.run:)com.google.android.gms.dynamite_mapsdynamite@[email protected] (040408-213742215):4)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference
at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:182)
... 13 more
 

Richard Goh

Active Member
Licensed User
Longtime User
Hi buras3,
Thanks for the reply. I tested and it's not related to permission issue. It's as Erel replied on this post.
https://www.b4x.com/android/forum/threads/googlemaps-exception-after-updating-to-b4x-v6.69476/#content

Now I use 1.bas in this example program to test. https://www.b4x.com/android/forum/threads/google-maps-with-fusedlocationprovider.83876/.
It's can show the maps successfully. But now I am facing another challenge to adding the location marker or position onto the map using this program. It's doesn't call to Map_Ready function. I doesn't use the Start_Service in the sample program to fetch the location.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    Wait For MapFragment1_Ready
    gmap = MapFragment1.GetMap
    If gmap.IsInitialized Then
     ......
     End If
End Sub

Sub Map_Ready
    Log("map ready")
    gmap = MapFragment1.GetMap
    If gmap.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    Else
        gmap.AddMarker(36, 15, "Hello!!!")
        Dim cp As CameraPosition
        cp.Initialize(36, 15, gmap.CameraPosition.Zoom)
        gmap.AnimateCamera(cp)
    End If
End Sub
 
Upvote 0

Richard Goh

Active Member
Licensed User
Longtime User
Hi, I managed to resolve the problem. It's due to my MapFragment1 declaration not same as the name in designer view. So it's not able to trigger the Map_ready.
Sory for the trouble. Thank you.
 
Upvote 0
Top