Android Question [ Verso and GeoLocation ] Problems on receive city name on both libs

Waldemar Lima

Well-Known Member
Licensed User
hello everyone !
i am trying use libraryes called > Verso and GeoLocation by @DonManfred to get my Address , City and State info

Verso Code >
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim verso As Verso
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")
    verso.Initialize("Verso")
    verso.getGeoInfo(50.8293765,6.4325835)
End Sub
Sub Verso_geoinfo(geo As GeoInfo)
    Log($"Verso_geoinfo()"$)
    Log(geo.CityName)
    Log(geo.CountryCode)
    Log(geo.CountryName)
    Log(geo.isMajorPlace)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

When code runto geo.CityName show this log:
B4X:
Logger connected to:  Xiaomi Mi 9T
--------- beginning of main
*** Service (starter) Create ***
--------- beginning of system
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Verso_geoinfo()
Error occurred on line: 35 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String de.donmanfred.GeoInfoWrapper.getCityName()' on a null object reference
    at b4a.example.main._verso_geoinfo(main.java:427)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7520)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)


same with GeoLocation , Code below :

B4X:
#Region  Project Attributes
    #ApplicationLabel: GeoLoc
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: true
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Public GeoLoc As GeoLocator

    Private btnAddress As Button
    Private btnCheck As Button
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")
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        GeoLoc.Initialize("GeoLocation")
    Else
        Log("NoPermission")
    End If
End Sub
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String, isMockLocation As Boolean)
    Log($"GeoLocation_Location(${success}, ${Lattitude}, ${Longitude}, ${info}, ${isMockLocation})"$)
    If success Then
        GeoLoc.geoAddress
        Log(GeoLoc.Address)
        Log(GeoLoc.Country)
        Log(GeoLoc.KnownName)
        Log(GeoLoc.PostalCode)
        Log(GeoLoc.State)
        Log(GeoLoc.City)

    End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnAddress_Click
    GeoLoc.geoAddress2(50.7702762,6.0745401)
End Sub

Sub btnCheck_Click
    'GeoLoc.geoAddress
    Log(GeoLoc.Address)
    Log(GeoLoc.City)
    Log(GeoLoc.Country)
    Log(GeoLoc.KnownName)
    Log(GeoLoc.PostalCode)
    Log(GeoLoc.State)

End Sub

and log of geolocation below :

B4X:
Logger connected to:  Xiaomi Mi 9T
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
GeoLocation_Location(true, xx.xxx1xx5, xx.xxx8xx3, GPS_PROVIDER, false)
addresses:1
Avenue ZZZXXXXXCCCC, 8951 - MainStreet , CITYLAND - UF, xxxxx-xxx, Brazil
Brazil
8951
xxxxxxx-xxx
UF
Error occurred on line: 48 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
    at anywheresoftware.b4a.BA.addLogPrefix(BA.java:604)
    at anywheresoftware.b4a.keywords.Common.LogImpl(Common.java:191)
    at b4a.example.main._geolocation_location(main.java:562)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7520)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

have a way to fix it ?
 
Last edited:
Top