https://kotlinlang.org logo
Title
i

IsaacMart

05/25/2023, 10:46 AM
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

lazynoda

05/26/2023, 7:24 AM
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

IsaacMart

05/26/2023, 8:36 AM
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