Hello guys. Am implementing Autocomplete for plac...
# android
i
Hello guys. Am implementing Autocomplete for places in compose android,but anytime i enter a letter in the search bar, the app crushes. I have followed the docs and initialized places with an API key but it seems that my intent reault is null. Below is my code snippet. // Initialize Map api Places.initialize(context, Constants.MAP_API_KEY) val launcher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() ) { result -> if (result.resultCode == 2) { val place = Autocomplete.getPlaceFromIntent(result.data) place.address?.let {address -> RequestServiceFormEvent.TaskLocationChanged( address ) } } } Caused by: java.lang.NullPointerException: Intent expected to contain a Place, but doesn't. help me solve this error
l
Why are you checking
resultCode == 2
? Shouldn't it be
resultCode == Activity.RESULT_OK
(which is
-1
)? Apart from that, how are you launching the intent? Maybe the issue is there
i
I did try it with resultCode== Activity. RESULT_OK. This was after countless tries. Appologies i posted the question with an error. After research, i have also found that this is a common bug and am working on a new alternative to it. I will post a link to tye alternative approach to it so that it can help someone also. Thanks David for the assistance