Android Question Object should first be initialized (Location)

DickD

Active Member
Licensed User
******* UPDATE: After rebooting the phone this error has gone away?????

I am using FusedLocationProvider. It works just fine on a Samsung S6 phone with Android 7.0. However on a Moto Droid phone with Android 6.0.1 I get the error shown in the topic. The code is shown below. I have tried it with and without an .initialize statement in various locations without success. On the Samsung there is no .init statement and it works well.

B4X:
Sub FLP_ConnectionSuccess()
 Log("FLP_ConnectionSuccess")
 LastLocation.Initialize ' (this doesn't seem to help)
 LastLocation = FLP.GetLastKnownLocation
 GetAddress(LastLocation.Latitude,LastLocation.longitude)
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
LastLocation.Initialize ' (this doesn't seem to help)
LastLocation = FLP.GetLastKnownLocation
This is a common mistake. There is no reason to initialize the variable if you are assigning a new one in the next line. If I remember correctly it is covered in this video tutorial:


Your code should be:
B4X:
 LastLocation = FLP.GetLastKnownLocation
If LastLocation.IsInitialized Then 
 ...
End If
 
Upvote 0
Top