I keep getting a null pointer exception i want to see if the response exists and if so println it out.
if (responsePlace.result.opening_hours.weekday_text.isNotEmpty() ){
println("The response for place time " responsePlace.result.opening_hours.weekday_text[0].toString())}
CodePudding user response:
you can try this :
responsePlace.let
{
when(it.isSuccessful) {
true -> println(""The response for place time " it.result.opening_hours.weekday_text[0].toString()")
false -> println("something went wrong!")
}
CodePudding user response:
Use the handy isNullOrEmpty()
method in kotlin.
So your method will look like
if (!responsePlace.result.opening_hours.weekday_text.isNullOrEmpty()){
println("The response for place time " responsePlace.result.opening_hours.weekday_text[0].toString())}
take care of the '!' negation at the start of the condition