Android Question Geocoder crashed B4A app [solved]

swChef

Active Member
Licensed User
Longtime User
update/summary: Geocoder would sometimes return nulls in some fields, and those were passed directly to log(), causing the crash. Updated the context here.

I threw together a Geofence + FusedLocationProvider + Geocoder + xChart in B4A to run some tests. First time I'm trying to do anything with any of these. Had it running around the house for a few days as I pulled this together, seeing how well the FLP and fences work in a building. Today for the first time I took it on the road. Seemed to be working fine. Then about a half-mile away from my starting point it crashed. The crash is reproducible; restarting it then continuing driving after a few minutes it crashes again. The Main activity was up at the time each time.

It's just a test app to exercise these services and see if I want to add them into an app I use. No crashes while having it on around the house. No other hints in the unfiltered log (although I didn't freshly crash it and check again, this content is from a few hours earlier). [turns out this was a clue - the geocoder address information was stable and completely filled out while stay in/around the building].

When I did look at it (was driving after all) in the first 1/4 to 1/2 mile it was running just fine and charting the samples as expected. Next glance and it was crashed.
 
Last edited:

swChef

Active Member
Licensed User
Longtime User
Sorry, that was release mode. But with BridgeLogger: True.
I was nowhere near enough to be connected to the debugger (wifi), and had my phone wifi turned off, when I did launch and start the test.
I'll try it again w/o BridgeLogger, and, to assure it wasn't in release mode.
On a second identical hw/android phone, the app ran all night w/o issue, but with wifi on and on the desk in the building. I'll leave it running and take it along on the drive test.

Update: BridgeLogger didn't make a difference (but you knew that)
 
Last edited:
Upvote 0

swChef

Active Member
Licensed User
Longtime User
Geocoder was at times returning Results with some of the entries set to null (ie, such as Thoroughfare or SubThoroughfare) and the B4A log operation is attempting to check string length on the null.
Erel, could you have the LogImpl/addLogPrefix check for null on the passed 'string' and just log 'null' ? I imagine this affects anytime a null is passed to Log.

B4X:
flpservice_geocoder1_geocodedone (java line: 411)
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.geofence.flpservice._geocoder1_geocodedone(flpservice.java:411)

from for example the Log(SubThoroughfare) taken from this post
B4X:
                Log(Results(0).Thoroughfare)
                Log(Results(0).SubThoroughfare)
                etc

I switched to a private sub instead and worked around the issue.
B4X:
Private Sub LogNullCheck(sItem As String, s As String)
    If s=Null Then
        Log("=> " & sItem & " 'null'")
    Else
        Log(s)
    End If
End Sub

=> thoroughfare 'null'
 
Upvote 0

swChef

Active Member
Licensed User
Longtime User
Yes I would prefer the geocoder library implement the fix.
Reading the geocoder doc it does describe the nulls.
Always read the docs aka RTFM
 
Last edited:
Upvote 0
Top